diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..c9a5ac89 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,49 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +let mole = { + title: "Mole", + serves: "2", + ingredients: ["cinnamon", "cumin", "cocoa"], + +} +console.log(mole.title); +console.log(`Serves: ${mole.serves}`); +console.log("Ingredients:") +mole.ingredients.forEach((ingredient) => { + console.log(ingredient); +}); + + +let pannaCota = { + title: "Panna Cotta", + serves: "4", + cookingTime: " 5 min", + ingredients: ["milk", "gelatine", "strawberry", "lemon", "sugar", "double cream", "vanilla"], +} +console.log(pannaCotta.title); +console.log(`Serves: ${pannaCotta.serves}`); +console.log("Ingredients:") +pannaCotta.ingredients.forEach((ingredient) => { + console.log(ingredient); +}); + +let byrek = { + title: "Byrek", + serves: "4", + prepTime="30min", + cookingTime: "30 min", + doughIngredients={ + ["water", "flour", "salt"], + }, + filling=["spinach", "spring onions", "feta", "salt", "olive oil"], + +} + +console.log(byrek.title); +console.log(`Serves: ${byrek.serves}`); +console.log("Ingredients:") +byrek.doughIngredients.forEach((ingredient) => { + console.log(ingredient); +}); \ 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..ac6f78eb 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -17,10 +17,26 @@ const COUNTRY_CURRENCY_CODES = [ ["MX", "MXN"], ]; -function createLookup(countryCurrencyCodes) { - // write code here +// function createLookup(countryCurrencyCodes) { +// currencyPairs = {} + +// countryCurrencyCodes.forEach(([el,curr])=>{ +// currencyPairs[el]=curr +// }) +// return currencyPairs; + +// } + +function createLookup(countryCurrencyCodes){ + 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` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..f20bcd97 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,8 +19,21 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here -} + let shoppingList = {}; + shoppingList.items = []; + shoppingList.name = recipe.name + // check ungredients + 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` diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..867a4b80 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,7 +20,22 @@ const MENU = { }; 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 ===== diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..389057bd 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,33 +43,51 @@ 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)).toBe("B"); /* Remove the .skip above, then write the test body. */ }); /* 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 */ - +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 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 diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..cd8ac9f9 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) { @@ -56,6 +56,12 @@ function formatCourseworkResult(trainee) { } */ +test("formatCourseworkResult returns the correct string for trainee Xin", () => { + const trainee = { name: "Xin", score: 63 }; + const result = formatCourseworkResult(trainee); + expect(result).toBe("Xin's coursework was marked as grade C."); +}); + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: { @@ -63,7 +69,11 @@ function formatCourseworkResult(trainee) { score: 78 } */ - +test("formatCourseworkResult returns the correct string for trainee Mona", () => { + const trainee = { name: "Mona", score: 78 }; + const result = formatCourseworkResult(trainee); + expect(result).toBe("Mona's coursework was marked as grade B."); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: { @@ -74,6 +84,13 @@ function formatCourseworkResult(trainee) { } */ + test("trainee with score 49 is grade E", () => { + const trainee = { name: "Ali", score: 49, age: 33, subjects: ["JavaScript", "React", "CSS"] }; + const expectedOutput = "Ali's coursework was marked as grade E."; + const result = formatCourseworkResult(trainee); + expect(result).toEqual(expectedOutput); + }); + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: { @@ -81,6 +98,13 @@ function formatCourseworkResult(trainee) { age: 29 } */ +test("formatCourseworkResult returns the correct string for trainee with no name but a valid score", () => { + const trainee = { score: 90, age: 29 }; + const result = formatCourseworkResult(trainee); + expect(result).toBe("Error: No trainee name!"); +}); + + /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -89,3 +113,8 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test("formatCourseworkResult returns the correct string for trainee Aman with no score", () => { + const trainee = { name: "Aman", subjects: ["HTML", "CSS", "Databases"] }; + const result = formatCourseworkResult(trainee); + expect(result).toBe("Error: Coursework percent is not a number!"); +});