From 2b62498d28f89036b1db9a75a3d7ac49688a912e Mon Sep 17 00:00:00 2001 From: Hussein Date: Sat, 1 Apr 2023 03:41:22 +0100 Subject: [PATCH 1/6] mandatory 1 done --- 2-mandatory/1-recipes.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..8f0fe086 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,40 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +let coffee = { + title: "cup of coffee", + serving: 1, + ingredients: ["coffee", "sugar", "hot water", "milk"], +}; + +let tea = { + title: "cup of tea", + serving: 1, + ingredients: ["tea bag", "hot water", "honey"], +}; + +let glassOfWater = { + title: "water", + serving: 1, + ingredients: ["water", "cup"], +}; + +let boiledEgg = { + title: "egg", + serving: 1, + ingredients: ["egg", "boiling water"], +}; + +let bread = { + title: "bread", + serving: 1, + ingredients: ["flour", "water"], +}; + + + +console.log([coffee]) +console.log([tea]) +console.log([glassOfWater]) +console.log([boiledEgg]) +console.log([bread]) From 0f0398a35ee6cfb4308adab2fc1ec044c68ffd84 Mon Sep 17 00:00:00 2001 From: Hussein Date: Sat, 1 Apr 2023 04:09:37 +0100 Subject: [PATCH 2/6] mand. 2nd done --- 2-mandatory/2-currency-code-lookup.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..402461f3 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,9 +18,16 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + let lookup = {}; + + for (const [countryCode, currencyCode] of countryCurrencyCodes) { + lookup[countryCode] = currencyCode; + }; + + return lookup; } + /* ======= 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` From 45f4870005a8fcc45551d5ba9c90809d5cd9d70d Mon Sep 17 00:00:00 2001 From: Hussein Date: Sat, 1 Apr 2023 22:31:13 +0100 Subject: [PATCH 3/6] mand. 3rd done --- 2-mandatory/3-shopping-list.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..9fb78d03 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -10,7 +10,7 @@ The createShoppingList function should return an object with two properties: - "name" of the recipe, which is a string, - - "items", which is an arry of the missing ingredients that need to be on the shopping list + - "items", which is an array of the missing ingredients that need to be on the shopping list */ let pantry = { @@ -19,7 +19,17 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here + let shoppingList = { + name:recipe.name, + items:[], + }; + + for (let item of recipe.ingredients){ + if (!pantry.cupboardContents.includes(item) && !pantry.fridgeContents.includes(item)){ + shoppingList.items.push(item); + } + } + return shoppingList; } /* ======= TESTS - DO NOT MODIFY ===== From 229c28cf3d69820950b028a23702ed80df34d1ff Mon Sep 17 00:00:00 2001 From: Hussein Date: Sun, 2 Apr 2023 23:37:19 +0100 Subject: [PATCH 4/6] mand 4 done --- 2-mandatory/4-restaurant.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..14522d20 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,23 @@ const MENU = { }; let cashRegister = { - // write code here -} + + orderBurger: function(balance) { + if (balance - MENU.burger >= 0) { + balance = balance - MENU.burger; + }; + return balance; + + }, + + orderFalafel: function(balance) { + if (balance - MENU.falafel >= 0) { + balance = balance - MENU.falafel; + }; + return balance; + }, + +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` From fcaf1a1052964d7771c7282d962033b688eab93d Mon Sep 17 00:00:00 2001 From: Hussein Date: Sun, 2 Apr 2023 23:52:33 +0100 Subject: [PATCH 5/6] mand 5 done --- 2-mandatory/5-writing-tests.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..b96aa41f 100644 --- a/2-mandatory/5-writing-tests.js +++ b/2-mandatory/5-writing-tests.js @@ -35,7 +35,7 @@ function convertScoreToGrade(score) { passes. */ test("a score of 83 is grade A", () => { - expect(convertScoreToGrade(83), "Z"); + expect(convertScoreToGrade(83)).toBe("A"); }); /* @@ -43,17 +43,21 @@ test("a score of 83 is grade A", () => { write a matching test */ -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)).toBe("B"); }); /* Write a test that checks a score of 68 is grade C */ - +test("a score of 68 is grade C", () => { + expect(convertScoreToGrade(68)).toBe("C"); +}); /* Write a test that checks a score of 55 is grade D */ - +test("a score of 55 is grade D", () => { + expect(convertScoreToGrade(55)).toBe("D"); +}); /* Write a test that checks a score of 68 is grade C */ @@ -65,11 +69,18 @@ test.skip("a score of 71 is grade B", () => { /* Write a test that checks a score of 49 is grade E */ - +test("a score of 49 is grade E", () => { + expect(convertScoreToGrade(49)).toBe("E"); +}); /* Write a test that checks a score of 30 is grade E */ - +test("a score of 30 is grade E", () => { + expect(convertScoreToGrade(30)).toBe("E"); +}); /* Write a test that checks a score of 70 is grade B */ +test("a score of 70 is grade B", () => { + expect(convertScoreToGrade(70)).toBe("B"); +}); \ No newline at end of file From 9521d3052b84bcb3116ebaee6752f380b56f0129 Mon Sep 17 00:00:00 2001 From: Hussein Date: Mon, 3 Apr 2023 00:29:08 +0100 Subject: [PATCH 6/6] mand 6 and last done --- 2-mandatory/6-writing-tests-advanced.js | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..d02d396b 100644 --- a/2-mandatory/6-writing-tests-advanced.js +++ b/2-mandatory/6-writing-tests-advanced.js @@ -10,7 +10,7 @@ trainee has completed. */ -function convertScoreToGrade() { +function convertScoreToGrade(score) { let grade = null; if (score >= 80) { @@ -55,6 +55,13 @@ function formatCourseworkResult(trainee) { score: 63 } */ +let trainee1 = { + name: "Xin", + score: 63, + } +test("if Xin's grade is C", () => { + expect(formatCourseworkResult(trainee1)).toBe("Xin's coursework was marked as grade C."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -63,6 +70,13 @@ function formatCourseworkResult(trainee) { score: 78 } */ +let trainee2 = { + name: "Mona", + score: 78, + } +test("if Mona's grade is B", () => { + expect(formatCourseworkResult(trainee2)).toBe("Mona's coursework was marked as grade B."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -73,6 +87,13 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ +let trainee3 = { + name: "Ali", + score: 49, + } +test("if Ali's grade is E", () => { + expect(formatCourseworkResult(trainee3)).toBe("Ali's coursework was marked as grade E."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -81,6 +102,13 @@ function formatCourseworkResult(trainee) { age: 29 } */ +let trainee4 = { + + score: 90, + } +test("if trainee's name isn't provided", () => { + expect(formatCourseworkResult(trainee4)).toBe("Error: No trainee name!"); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -89,3 +117,9 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +let trainee5 = { + name: "Aman", + } +test("if trainee's score isn't provided", () => { + expect(formatCourseworkResult(trainee5)).toBe("Error: Coursework percent is not a number!"); +}); \ No newline at end of file