-
-
Notifications
You must be signed in to change notification settings - Fork 265
London 10 | Abubakar-Meigag | JS 2 - wk 1 #251
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,10 +17,36 @@ const COUNTRY_CURRENCY_CODES = [ | |
| ["MX", "MXN"], | ||
| ]; | ||
|
|
||
|
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 to me! I like your use of the |
||
| function createLookup(countryCurrencyCodes) { | ||
| // write code here | ||
| function createLookup(countryCurrencyCodes){ | ||
| let resultLookup = {}; | ||
| countryCurrencyCodes.forEach(([el, curr]) => { | ||
| resultLookup[el] = curr | ||
| }); | ||
| return resultLookup | ||
| } | ||
|
|
||
|
|
||
| //------>>> another solution | ||
|
|
||
| // function createLookup(countryCurrencyCodes) { | ||
| // let countryCurrencyCodesLookup = {}; | ||
| // for (let countryCurrencyCode of countryCurrencyCodes) { | ||
| // countryCurrencyCodesLookup[countryCurrencyCode[0]] = | ||
| // countryCurrencyCode[1]; | ||
| // } | ||
| // return countryCurrencyCodesLookup; | ||
| // } | ||
|
|
||
| //------>>> another solution | ||
|
|
||
| // function createLookup(COUNTRY_CURRENCY_CODES) { | ||
| // const country = new Map(COUNTRY_CURRENCY_CODES); | ||
| // const obj = Object.fromEntries(country); | ||
| // return obj | ||
| // } | ||
|
|
||
|
|
||
|
|
||
| /* ======= 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` | ||
|
|
@@ -34,4 +60,4 @@ test("creates country currency code lookup", () => { | |
| NG: "NGN", | ||
| MX: "MXN", | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,26 @@ let pantry = { | |
| cupboardContents: ["salt", "tinned tomatoes", "oregano"], | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| 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. The implementation looks good to me. For an extra challenge - can you implement this using the |
||
| let shoppingList = {}; | ||
| shoppingList.items =[]; | ||
| shoppingList.name = recipe.name | ||
| // check ingredients | ||
| for (let ingredient of recipe.ingredients) | ||
| { | ||
|
|
||
| if ( !pantry.fridgeContents.includes(ingredient) | ||
| && !pantry.cupboardContents.includes(ingredient)) { | ||
|
|
||
| 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` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,23 @@ const MENU = { | |
| }; | ||
|
|
||
|
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. Perfect! |
||
| let cashRegister = { | ||
| // write code here | ||
| 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; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` | ||
| - To run all exercises/tests in the mandatory folder, run `npm test` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,41 +35,64 @@ function convertScoreToGrade(score) { | |
| passes. | ||
| */ | ||
| test("a score of 83 is grade A", () => { | ||
| expect(convertScoreToGrade(83), "Z"); | ||
| expect(convertScoreToGrade(83)).toBe("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. These tests look good 👍 |
||
| test.skip("a score of 71 is grade B", () => { | ||
| test("a score of 71 is grade B", () => { | ||
| expect(convertScoreToGrade(71)).toBe("B"); | ||
| /* Remove the .skip above, then write the test body. */ | ||
| }); | ||
| /* | ||
|
|
||
| test("a score of 68 is grade C", () => { | ||
| expect(convertScoreToGrade(68)).toBe("C"); | ||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
| }); | ||
|
|
||
| test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toBe("D"); | ||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
| }); | ||
|
|
||
| test("a score of 68 is grade C", () => { | ||
| expect(convertScoreToGrade(68)).toBe("C"); | ||
| /* | ||
| Write a test that checks a score of 68 is grade C | ||
| */ | ||
| }); | ||
|
|
||
| test("a score of 55 is grade D", () => { | ||
| expect(convertScoreToGrade(55)).toBe("D"); | ||
| /* | ||
| Write a test that checks a score of 55 is grade D | ||
| */ | ||
| }); | ||
|
|
||
| test("a score of 49 is grade E", () => { | ||
| expect(convertScoreToGrade(49)).toBe("E"); | ||
| /* | ||
| Write a test that checks a score of 49 is grade E | ||
| */ | ||
| }); | ||
|
|
||
| test("a score of 30 is grade E", () => { | ||
| expect(convertScoreToGrade(30)).toBe("E"); | ||
| /* | ||
| Write a test that checks a score of 30 is grade E | ||
| */ | ||
| }); | ||
|
|
||
| /* | ||
| test("a score of 70 is grade B", () => { | ||
| expect(convertScoreToGrade(70)).toBe("B"); | ||
| /* | ||
| Write a test that checks a score of 70 is grade 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) { | ||
|
|
@@ -55,6 +55,16 @@ function formatCourseworkResult(trainee) { | |
| score: 63 | ||
| } | ||
| */ | ||
| test("Trainee Xin, score of 63",() =>{ | ||
| let trainee = { | ||
| name: "Xin", | ||
| score: 63, | ||
| }; | ||
| expect(formatCourseworkResult(trainee)).toEqual( | ||
| `${trainee.name}'s coursework was marked as grade C.` | ||
| ); | ||
| }); | ||
|
|
||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -63,6 +73,12 @@ function formatCourseworkResult(trainee) { | |
| score: 78 | ||
| } | ||
| */ | ||
| test(`trainee Mona, score is 78`,() => { | ||
| let trainee ={ name:`Mona`, score: 78,} | ||
| expect(formatCourseworkResult(trainee)).toEqual( | ||
| `${trainee.name}'s coursework was marked as grade B.` | ||
| ); | ||
| }) | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -73,6 +89,17 @@ function formatCourseworkResult(trainee) { | |
| subjects: ["JavaScript", "React", "CSS"] | ||
| } | ||
| */ | ||
| test(`trainee Ali , score is 49`, () => { | ||
| let trainee = { | ||
| name: "Ali", | ||
| score: 49, | ||
| age: 33, | ||
| subjects: ["JavaScript", "React", "CSS"], | ||
| }; | ||
| expect(formatCourseworkResult(trainee)).toEqual( | ||
| `${trainee.name}'s coursework was marked as grade E.` | ||
| ); | ||
| }) | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -81,6 +108,14 @@ function formatCourseworkResult(trainee) { | |
| age: 29 | ||
| } | ||
| */ | ||
| test("Trainee , score of 90", () => { | ||
| let trainee = { | ||
| score: 90, | ||
| age: 29, | ||
| }; | ||
| expect(formatCourseworkResult(trainee)).toEqual( | ||
| `Error: No trainee name!`); | ||
| }); | ||
|
|
||
| /* | ||
| Write a test that checks the output of formatCourseworkResult when passed the following trainee: | ||
|
|
@@ -89,3 +124,12 @@ function formatCourseworkResult(trainee) { | |
| subjects: ["HTML", "CSS", "Databases"] | ||
| } | ||
| */ | ||
|
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 tests look good - but have a think about the best way to name the tests. |
||
| test("Trainee Aman, score of ", () => { | ||
| 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.
Nice 👍