From ee73e9b08e13bda2050694528ce16640eacd23a4 Mon Sep 17 00:00:00 2001 From: Ehdaa Munier <109866621+Ehdaa-Munier@users.noreply.github.com> Date: Tue, 11 Apr 2023 23:18:31 +0100 Subject: [PATCH] mandatory 1,2,3,4,5,6 has done --- 2-mandatory/1-recipes.js | 13 +++++++- 2-mandatory/2-currency-code-lookup.js | 7 ++++ 2-mandatory/3-shopping-list.js | 12 +++++++ 2-mandatory/4-restaurant.js | 22 ++++++++++++- 2-mandatory/5-writing-tests.js | 34 ++++++++++++++++--- 2-mandatory/6-writing-tests-advanced.js | 43 ++++++++++++++++++++++++- 6 files changed, 123 insertions(+), 8 deletions(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..d1774e92 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,15 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +let Recipe = { + title: "Mole" , //(a string), + servings: 2 , //a number), and + ingredients: ["cinnamon", "cumin", "cocoa"] //(an array of strings) + +}; +console.log(Recipe.title); +console.log(`Serves: ${Recipe.servings}`); +console.log(Recipe.ingredients[0]); +console.log(Recipe.ingredients[1]); +console.log(Recipe.ingredients[2]); \ No newline at end of file diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..0ed9ca4f 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,13 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + + let res = {}; + for( let [countrycodes, currencycodes] of countryCurrencyCodes){ + + res[countrycodes] = currencycodes; + }; + return res; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..823af93d 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,7 +19,19 @@ let pantry = { }; function createShoppingList(recipe) { + // write code here + let shoppingList={ + name: recipe.name, + items:[] + } + for (let items of recipe.ingredients) { + if (!pantry.fridgeContents.includes(items) && !pantry.cupboardContents.includes(items)) { + shoppingList.items.push(items); + } + + } + return shoppingList; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..93a31a82 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,28 @@ const MENU = { }; let cashRegister = { + orderBurger:function(balance){ + let finalBalance=balance; + let isBalanceBigEnough = balance - MENU.burger >= 0; + if (isBalanceBigEnough) { + finalBalance = balance - MENU.burger; + } + return finalBalance; + }, + + orderFalafel: function(balance){ + let finalBalance = balance; + let isBalanceBigEnough = balance - MENU.falafel >= 0; + if (isBalanceBigEnough) { + finalBalance = balance - MENU.falafel; + } + return finalBalance + } + + + } // write code here -} + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..cb0b53ec 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)).toEqual("A"); }); /* @@ -43,33 +43,57 @@ test("a score of 83 is grade A", () => { write a matching test */ -test.skip("a score of 71 is grade B", () => { +test("a score of 71 is grade B", () => { + expect(convertScoreToGrade(71)).toEqual("B"); /* Remove the .skip above, then write the test body. */ }); -/* - 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 55 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 */ +test("a score of 68 is grade D", () => { + expect(convertScoreToGrade(55)).toEqual("D"); +}); /* Write a test that checks a score of 49 is grade E */ +test("a score of 68 is grade E", () => { + expect(convertScoreToGrade(49)).toEqual("E"); +}); /* Write a test that checks a score of 30 is grade E */ - +test("a score of 68 is grade E", () => { + expect(convertScoreToGrade(30)).toEqual("E"); +}); /* Write a test that checks a score of 70 is grade B */ +test("a score of 68 is grade B", () => { + expect(convertScoreToGrade(70)).toEqual("B"); +}); \ No newline at end of file diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..3d3c75cd 100644 --- a/2-mandatory/6-writing-tests-advanced.js +++ b/2-mandatory/6-writing-tests-advanced.js @@ -55,6 +55,14 @@ function formatCourseworkResult(trainee) { score: 63 } */ +test("Xin's score returns the correct sentence", () => { + expect( + formatCourseworkResult({ + name: "Xin", + score: 63, + }) + ).toEqual("Xin's coursework was marked as grade C."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -63,7 +71,14 @@ function formatCourseworkResult(trainee) { score: 78 } */ - +test("Mona's score returns the correct sentence", () => { + expect( + formatCourseworkResult({ + name: "Mona", + score: 78, + }) + ).toEqual("Mona's coursework was marked as grade B."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: { @@ -73,6 +88,16 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ +test("Ali's score returns the correct sentence", () => { + expect( + formatCourseworkResult({ + name: "Ali", + score: 49, + age: 33, + subjects: ["JavaScript", "React", "CSS"] + }) + ).toEqual("Ali's coursework was marked as grade D."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -81,6 +106,14 @@ function formatCourseworkResult(trainee) { age: 29 } */ +test("test object with no name", () => { + 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 +122,11 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test("test object with no score", () => { + let trainee = { + name: "Aman", + subjects: ["HTML", "CSS", "Databases"] + }; + + expect(formatCourseworkResult(trainee)).toEqual("Error: No trainee score!"); +}); \ No newline at end of file