Skip to content

This PR is the solution to the 'js basics' #1 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions 1-js-basics/solutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Data_types:
```
Data Types one would need to build a shopping cart:

Numbers --> for the number of items in cart
for the quantity of each item in cart
for the price of each product

Strings --> to display the name of the item in the cart

Boolean --> to check which items are selected for purchase
to check weather the minimum order quantity/amount has been fulfilled

Date --> to display the estimated delivery date
```

--------------------------------------------------------------------------------

Function_methods:

``` javascript
function displayGreeting(name, pronoun= "Mr.") {

console.log(`Good morning, ${pronoun} ${name}!`);
}
displayGreeting('Sravan');
displayGreeting('sravan lol', good ='Mrs.');



let num_1 = 25;
let num_2 = 30;
let operator = '+';
let result;

function arthematicSolve(number_1, number_2, operator){
switch(operator){
case "+":
result = number_1+number_2;
break;
case "-":
result = number_1-number_2;
break;
case "x":
result = number_1*number_2;
break;
case "/":
result = number_1/number_2;
break;
}
return result;
}
console.log(arthematicSolve(num_1,num_2,operator));
```

----------------------------------------------------------------------------

Making-decisions:

``` javascript
let allStudents = ['A','B-',1,4,5,2];
let studentsWhoPass = [];
let j;

function gradingSystem(allGrades){
for (let i=0; i<allStudents.length; i++){
j = allStudents[i];
if (typeof j === 'number'){
if (j>=3){
studentsWhoPass.push(j);
}
}
else{
switch(j){
case "A":
studentsWhoPass.push(j);
break;
case "A-":
studentsWhoPass.push(j);
break;
case "B":
studentsWhoPass.push(j);
break;
case "B-":
studentsWhoPass.push(j);
break;
case "C":
studentsWhoPass.push(j);
break;
}
}
}
}
gradingSystem(allStudents);
console.log(studentsWhoPass);
```

-----------------------------------------------------------------------------

Array-loops:

``` javascript

let listNumbers = [];
function everyThirdNumber(){
for(let i =1; i<21; i+=3){
listNumbers.push(i);
}
}
everyThirdNumber();
console.log(listNumbers);

```