Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit b887d86

Browse files
committed
finished all tha home work for javascript1 week 2
1 parent 8aa0422 commit b887d86

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
11
'use strict'
2+
// this solution we took it in the session on Sunday because it does not make any sence to loop throgh only one object
3+
4+
5+
/*
6+
const pizzaRecipe = {};
7+
pizzaRecipe.title = 'Pizza';
8+
pizzaRecipe.servings = 1;
9+
pizzaRecipe.ingredients = ['Flower', 'Tomato Sauce', 'Mushroom', 'Mozzarella'];
10+
11+
const falafelRecipe = {};
12+
falafelRecipe.title = 'Falafel';
13+
falafelRecipe.servings = 8;
14+
falafelRecipe.ingredients = ['Chickpeas', 'Tahine', 'Spices'];
15+
16+
const recipes = [
17+
pizzaRecipe,
18+
falafelRecipe
19+
];
20+
21+
recipes.forEach(recipe => {
22+
console.log('Meal Name :',recipe.title);
23+
console.log('Servings :', recipe.servings);
24+
const ingredientString = recipe.ingredients.join(", ");
25+
console.log('Ingredients :', ingredientString);
26+
})
27+
*/
28+
29+
// this way to solve the exercise is also discused in the sunday session
30+
31+
32+
const myMeal = {};
33+
myMeal.title = 'sapghetti with bashamel suce';
34+
myMeal.servings = 2;
35+
myMeal.ingredientString = ['spaghetti', 'Mashroum', 'bahsamel souce'];
36+
console.log("meal title: "+ myMeal.title);
37+
console.log("meal servings: " + myMeal.servings);
38+
console.log("ingredient:" + myMeal.ingredientString.join(', '));
39+
40+
41+
/*acctually I dont understand why do we need to use a loop for this exercise if this way is not good
42+
pleas inform me so I can update it */

‎Week2/homework/exercises/ex4TheReadingBooks.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ let myBooks = [
3131
console.log("you still need to read "+'"' + myBooks[i].title + '"')
3232
}
3333
i++;
34-
}
34+
}
35+
36+
/* here i used 2 loops for tow reasons the first one is to improve my skills useing more than one type
37+
of loops and the secound reason is to make the console print this (For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".)
38+
and the secound loop to print this (log a string like You already read "The Hobbit" right after the log of the book details)
39+
*/

‎Week2/homework/gradeCalculater.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
// first I am going to declar a function that takes the student grades and the max grade
4+
5+
function americanGradeCalculator(studentGrade,maxGrade){
6+
7+
// here I will declare a variable to calculate the persentge grade
8+
9+
let percentage = (studentGrade/maxGrade) * 100;
10+
11+
// I will use switch statment so in every case the grade will give a defiirent percentage based on the student grade
12+
13+
switch(true){
14+
case percentage >= 90: // from 90 to 100 it should return A then we break and go to next case
15+
return `You got a A ( ${percentage} %)!`;
16+
break;
17+
case percentage >= 80:
18+
return `You got a B ( ${percentage} %)!`;
19+
break;
20+
case percentage >= 70:
21+
return `You got a C ( ${percentage} %)!`;
22+
break;
23+
case percentage >= 60:
24+
return `You got a D ( ${percentage} %)!`;
25+
break;
26+
case percentage >= 50:
27+
return `You got a E ( ${percentage} %)!`;
28+
break;
29+
case percentage >= 0:
30+
return `You got a F ( ${percentage} %)!`;
31+
break;
32+
default: // here in case somone put a number that is not in tha cases it will show this message
33+
return "Please Enter A Valid Grade!";
34+
break;
35+
}
36+
}
37+
/* thanks to ianu he teached us how to writ the string in this way(`You got a F ( ${percentage} %)!`; )
38+
better than putting a lot of + inside it */

0 commit comments

Comments
 (0)