-
-
Notifications
You must be signed in to change notification settings - Fork 265
London 10-Anu Thapaliya-js2-week1 #249
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 |
|---|---|---|
|
|
@@ -17,9 +17,21 @@ const COUNTRY_CURRENCY_CODES = [ | |
| ["MX", "MXN"], | ||
| ]; | ||
|
|
||
|
|
||
|
|
||
| function createLookup(countryCurrencyCodes) { | ||
| // write code here | ||
| } | ||
|
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 👍 |
||
| let countryCurrencyCodesLookUp = {}; | ||
|
|
||
| for(let countryCurrencyCode of countryCurrencyCodes){ | ||
| countryCurrencyCodesLookUp[countryCurrencyCode[0]]=countryCurrencyCode[1]; | ||
|
|
||
| } | ||
|
|
||
| return countryCurrencyCodesLookUp; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,25 @@ let pantry = { | |
| }; | ||
|
|
||
| function createShoppingList(recipe) { | ||
| // write code here | ||
| } | ||
|
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 looks good to me 👍 |
||
| let shoppingList = {}; | ||
| shoppingList.items =[]; | ||
| shoppingList.name = recipe.name | ||
| // check ungredients | ||
| for (let ingredient of recipe.ingredients) | ||
| { | ||
|
|
||
| if (pantry.fridgeContents.includes(ingredient)=== false | ||
|
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. When you see something like this:
Author
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. ok great thank you |
||
| && pantry.cupboardContents.includes(ingredient)=== false) { | ||
|
|
||
| shoppingList.items.push(ingredient); | ||
|
|
||
| } | ||
| } | ||
| return shoppingList; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` | ||
|
|
@@ -43,11 +60,11 @@ test("createShoppingList works for pancakes recipe", () => { | |
| test("createShoppingList works for margherita pizza recipe", () => { | ||
| let recipe2 = { | ||
| name: "margherita pizza", | ||
| ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"], | ||
| ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella" ], | ||
| }; | ||
|
|
||
| expect(createShoppingList(recipe2)).toEqual({ | ||
| name: "margherita pizza", | ||
| items: ["flour", "yeast", "mozarella"] | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,44 @@ const MENU = { | |
| }; | ||
|
|
||
| let cashRegister = { | ||
| // write code here | ||
| } | ||
|
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. Looks good 👍 |
||
| orderBurger: function(balance){ | ||
| if(balance >= MENU.burger){ | ||
| return balance - MENU.burger | ||
| }else{ | ||
| return balance; | ||
| } | ||
| }, | ||
| orderFalafel: function(balance){ | ||
| if (balance >= MENU.falafel) { | ||
| return balance - MENU.falafel | ||
| }else{ | ||
| return balance; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // let coffeeMachine = { | ||
| // brand: "Super Coffee", | ||
| // prices: { | ||
| // cappuccino: 2.4, | ||
| // blackCoffee: 1.5, | ||
| // flatWhite: 3.0, | ||
| // }, | ||
| // insertedAmount: 0, | ||
| // insertMoney: function (amount) { | ||
| // this.insertedAmount += amount; // or this.insertedAmount = this.insertedAmount + amount; | ||
| // }, | ||
| // getCoffee: function (coffee) { | ||
| // if (this.insertedAmount >= this.prices[coffee]) { | ||
| // this.insertedAmount = 0; // insertedAmount resets after a transaction | ||
| // return `Please take your ${coffee}`; | ||
| // } else { | ||
| // return `Sorry you don't have enough money for a ${coffee}`; | ||
| // } | ||
| // }, | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,42 +34,59 @@ function convertScoreToGrade(score) { | |
| The first test has been written for you. You need to fix the test so that it | ||
| 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 | ||
| */ | ||
|
|
||
| test.skip("a score of 71 is grade B", () => { | ||
| /* Remove the .skip above, then write the test body. */ | ||
|
|
||
|
|
||
| // * 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 | ||
| */ | ||
|
|
||
|
|
||
| // 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 | ||
| */ | ||
|
|
||
| */test("a score of 68 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toEqual ("D"); | ||
| }); | ||
| /* | ||
| 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 | ||
| */ | ||
|
|
||
|
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. The tests above look good. |
||
| */test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)), ("D"); | ||
| }) | ||
| /* | ||
| Write a test that checks a score of 49 is grade E | ||
| */ | ||
|
|
||
| */test("a score of 49 is grade E", () => { | ||
| expect(convertScoreToGrade(49)), ("E"); | ||
| }) | ||
| /* | ||
| Write a test that checks a score of 30 is grade E | ||
| */ | ||
| */test("a score of 30 is grade E", () => { | ||
| expect(convertScoreToGrade(30)), ("E"); | ||
| }) | ||
|
|
||
| /* | ||
| Write a test that checks a score of 70 is grade B | ||
| */ | ||
| */test("a score of 70 is grade B", () => { | ||
| expect(convertScoreToGrade(70)), ("B"); | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| trainee has completed. | ||
| */ | ||
|
|
||
| function convertScoreToGrade() { | ||
| function convertScoreToGrade(score) { | ||
| let grade = null; | ||
|
|
||
| if (score >= 80) { | ||
|
|
@@ -54,25 +54,39 @@ function formatCourseworkResult(trainee) { | |
| name: "Xin", | ||
| score: 63 | ||
| } | ||
| */ | ||
|
|
||
| /* | ||
|
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. These are great, well done! |
||
| */test("a score of 63 is grade C", () => { | ||
| const trainee = { name: "Xin", score: 63 }; | ||
| expect(formatCourseworkResult(trainee)).toEqual( | ||
| "Xin's coursework was marked as grade C." | ||
| ); | ||
| });/* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
| { | ||
| name: "Mona", | ||
| score: 78 | ||
| } | ||
| */ | ||
| */test("a score of 78 is grade B", () => { | ||
| let trainee = { name: "Mona", score: 78 }; | ||
| expect(formatCourseworkResult(trainee)). toEqual( | ||
| "Mona's coursework was marked as grade B." | ||
| ); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
| { | ||
| name: "Ali", | ||
| score: 49, | ||
| age: 33, | ||
| subjects: ["JavaScript", "React", "CSS"] | ||
| } | ||
| */ | ||
| test("a score of 49 is grade E", () => { | ||
| let trainee = {name:"Ali", score:49, age: 33, subjects:["JavaScript", "React", "CSS"]}; | ||
| expect(formatCourseworkResult(trainee)). toEqual( | ||
| "Ali's coursework was marked as grade E." | ||
| ); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -81,6 +95,11 @@ function formatCourseworkResult(trainee) { | |
| age: 29 | ||
| } | ||
| */ | ||
| test("object without name will fail error", () => { | ||
| let trainee = {score: 90, age: 20}; | ||
| expect(formatCourseworkResult(trainee)). toEqual("Error: No trainee name!") | ||
|
|
||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -89,3 +108,8 @@ function formatCourseworkResult(trainee) { | |
| subjects: ["HTML", "CSS", "Databases"] | ||
| } | ||
| */ | ||
| test("object without score is not a number", () => { | ||
| let trainee ={name: "Aman", subjects:["HTML", "CSS", "Databases"]}; | ||
| expect(formatCourseworkResult(trainee)). toEqual("Error: Coursework percent is not a number!"); | ||
|
|
||
| }); | ||
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.
The recipe objects look good 👍
But take another look at the instructions on lines 13-20. It looks each recipe should be output in this way: