-
-
Notifications
You must be signed in to change notification settings - Fork 264
London10-Afsha-Hossain-JS2-Week1 #239
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,77 @@ | |
| You should write and log at least 5 recipes | ||
| */ | ||
|
|
||
| let favouriteRecipe1 = {}; | ||
|
|
||
| favouriteRecipe1.title = "Mole"; | ||
| favouriteRecipe1.servings = 2; | ||
| favouriteRecipe1.ingredients = ["cinnamon", "cumin", "cocoa"]; | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we have a lot of duplicate code here to output a recipe in the format that we want. |
||
| console.log(favouriteRecipe1.title); | ||
| console.log(`serves: ${favouriteRecipe1.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let ingredient of favouriteRecipe1.ingredients) { | ||
| console.log(ingredient); | ||
| } | ||
|
|
||
| console.log(); | ||
|
|
||
| let favouriteRecipe2 = {}; | ||
|
|
||
| favouriteRecipe2.title = "Ramen"; | ||
| favouriteRecipe2.servings = 1; | ||
| favouriteRecipe2.ingredients = ["ramen cake", "egg", "spices", "chicken broth", "veggies"]; | ||
|
|
||
| console.log(favouriteRecipe2.title); | ||
| console.log(`serves: ${favouriteRecipe2.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let ingredient of favouriteRecipe2.ingredients) { | ||
| console.log(ingredient); | ||
| } | ||
|
|
||
| console.log(); | ||
|
|
||
| let favouriteRecipe3 = {}; | ||
|
|
||
| favouriteRecipe3.title = "Dried Mango"; | ||
| favouriteRecipe3.servings = 3; | ||
| favouriteRecipe3.ingredients = ["mango", "seasoning", "oil"]; | ||
|
|
||
| console.log(favouriteRecipe3.title); | ||
| console.log(`serves: ${favouriteRecipe3.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let ingredient of favouriteRecipe3.ingredients) { | ||
| console.log(ingredient); | ||
| } | ||
|
|
||
| console.log(); | ||
|
|
||
| let favouriteRecipe4 = {}; | ||
|
|
||
| favouriteRecipe4.title = "Cacao Cake"; | ||
| favouriteRecipe4.servings = 6; | ||
| favouriteRecipe4.ingredients = ["cacao", "maple syrup", "eggs", "coconut oil"]; | ||
|
|
||
| console.log(favouriteRecipe4.title); | ||
| console.log(`serves: ${favouriteRecipe4.servings}`); | ||
| console.log("ingredients: "); | ||
| for (let ingredient of favouriteRecipe4.ingredients) { | ||
| console.log(ingredient); | ||
| } | ||
|
|
||
| console.log(); | ||
|
|
||
| let favouriteRecipe5 = {}; | ||
|
|
||
| favouriteRecipe5.title = "Pad Thai"; | ||
| favouriteRecipe5.servings = 3; | ||
| favouriteRecipe5.ingredients = ["glass noodles", "sauce", "shrimp", "peanuts", "eggs", "garlic, veggies"]; | ||
|
|
||
| console.log(favouriteRecipe5.title); | ||
| console.log(`serves: ${favouriteRecipe5.servings}`); | ||
| console.log("Ingredients: "); | ||
| for (let ingredient of favouriteRecipe5.ingredients) { | ||
| console.log(ingredient); | ||
| } | ||
| // write code here | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,12 @@ const COUNTRY_CURRENCY_CODES = [ | |
| ]; | ||
|
|
||
| function createLookup(countryCurrencyCodes) { | ||
| return Object.fromEntries(countryCurrencyCodes); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever 😄 |
||
| // write code here | ||
| } | ||
|
|
||
| createLookup(COUNTRY_CURRENCY_CODES); | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` | ||
| - To run all exercises/tests in the mandatory folder, run `npm test` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,17 @@ let pantry = { | |
| }; | ||
|
|
||
| function createShoppingList(recipe) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation looks good to me! |
||
| let newItems = []; | ||
| for (let ingredient of recipe.ingredients) { | ||
| if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) { | ||
| newItems.push(ingredient); | ||
| } | ||
| } | ||
| let result = { | ||
| "name": recipe.name, | ||
| items: newItems, | ||
| } | ||
| return result; | ||
| // write code here | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,23 @@ const MENU = { | |
| }; | ||
|
|
||
| let cashRegister = { | ||
| // write code here | ||
| } | ||
| orderBurger: function(balance){ | ||
| if (balance >= MENU.burger) { | ||
| balance = balance - MENU.burger; | ||
| } else { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think the |
||
| balance = balance; | ||
| } | ||
| return (balance); | ||
| }, | ||
| orderFalafel: function(balance){ | ||
| if(balance >= MENU.falafel) { | ||
| balance = balance - MENU.falafel; | ||
| } else { | ||
| balance = balance; | ||
| } | ||
| return (balance); | ||
| } | ||
| }; | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` | ||
|
|
@@ -48,3 +63,4 @@ test("orderFalafel will not subtract from balance if balance is too low", () => | |
| let balance = 7.24; | ||
| expect(cashRegister.orderFalafel(balance)).toEqual(7.24); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,41 +35,49 @@ function convertScoreToGrade(score) { | |
| passes. | ||
| */ | ||
| test("a score of 83 is grade A", () => { | ||
| expect(convertScoreToGrade(83), "Z"); | ||
| expect(convertScoreToGrade(83)).toEqual("A"); | ||
| }); | ||
|
|
||
| /* | ||
| The rest of the tests have comments describing what to test and you need to | ||
| write a matching test | ||
| */ | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job 👍 |
||
| test.skip("a score of 71 is grade B", () => { | ||
| /* Remove the .skip above, then write the test body. */ | ||
| test("a score of 71 is grade B", () => { | ||
| expect(convertScoreToGrade(71)).toEqual("B"); | ||
| }); | ||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
| test("a score of 68 is grade C", () => { | ||
| expect(convertScoreToGrade(68)).toEqual("C"); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
|
|
||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
|
|
||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
| test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toEqual("D"); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks a score of 49 is grade E | ||
| */ | ||
| test("a score of 49 is grade E", () => { | ||
| expect(convertScoreToGrade(49)).toEqual("E"); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks a score of 30 is grade E | ||
| */ | ||
|
|
||
| test("a score of 30 is grade E", () => { | ||
| expect(convertScoreToGrade(30)).toEqual("E"); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks a score of 70 is grade B | ||
| */ | ||
| test("a score of 70 is grade B", () => { | ||
| expect(convertScoreToGrade(70)).toEqual("B"); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks correct to me 👍
One small comment - usually if you're defining an object and you already know the properties and values, it can be easier (to both write and read) to include all the information in your object definition. Using your example, this will look like: