From 73811aab5d5adc98ff39badb239ddd58bb6bf107 Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 13:45:21 +0000 Subject: [PATCH 1/6] Mandatory-recipes --- 2-mandatory/1-recipes.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..6b9e5bff 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,16 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +const recipe = { + title: "Mole", + servings: 2, + ingredients: ["cinnamon", "cumin", "cocoa"], +}; + +console.log(recipe.title); +console.log(`Serves: ${recipe.servings}`); +console.log( + `Ingredients:\n${recipe.ingredients[0]}\n${recipe.ingredients[1]}\n${recipe.ingredients[2]}` +); From 6cb464e327bd68cb2e5c3cb0be0e17a368d58fc1 Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 14:35:45 +0000 Subject: [PATCH 2/6] Mandatory-currency-code --- 2-mandatory/2-currency-code-lookup.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 5fde14f1..b42d2a35 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -19,6 +19,12 @@ const COUNTRY_CURRENCY_CODES = [ function createLookup(countryCurrencyCodes) { // write code here + const countryCurrencyObject = {}; + for (let arr of countryCurrencyCodes) { + countryCurrencyObject[arr[0]] = arr[1]; + } + + return countryCurrencyObject; } /* ======= TESTS - DO NOT MODIFY ===== @@ -34,4 +40,4 @@ test("creates country currency code lookup", () => { NG: "NGN", MX: "MXN", }); -}); \ No newline at end of file +}); From 3d3929f281e4e0b0e104d42796deb207cc16b983 Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:09:35 +0000 Subject: [PATCH 3/6] Mandatory-shopping-list --- 2-mandatory/3-shopping-list.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..ad71a55c 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -20,6 +20,16 @@ let pantry = { function createShoppingList(recipe) { // write code here + const newPantry = pantry.fridgeContents.concat(pantry.cupboardContents); + const missingItems = recipe.ingredients.slice(); + for (let item of recipe.ingredients) { + for (let i = 0; i < newPantry.length; i++) { + if (item == newPantry[i]) { + missingItems.splice(missingItems.indexOf(item), 1); + } + } + } + return { name: recipe.name, items: missingItems }; } /* ======= TESTS - DO NOT MODIFY ===== @@ -43,11 +53,18 @@ 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"] + items: ["flour", "yeast", "mozarella"], }); -}); \ No newline at end of file +}); From 97efc80205a2304da44baf29e4d68ce146b5b9a7 Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:23:36 +0000 Subject: [PATCH 4/6] Mandatory-restaurant --- 2-mandatory/4-restaurant.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..08ed9f28 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -21,7 +21,23 @@ const MENU = { let cashRegister = { // write code here -} + orderBurger: function (balance) { + if (balance - MENU.burger >= 0) { + let newBalance = balance - MENU.burger; + return newBalance; + } else { + return balance; + } + }, + orderFalafel: function (balance) { + if (balance - MENU.falafel >= 0) { + let newBalance = balance - MENU.falafel; + return newBalance; + } else { + return balance; + } + }, +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js` From 2090135c57999095a0c0ce9507f3dd5b60720f19 Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:40:06 +0000 Subject: [PATCH 5/6] Mandatory-writing-test --- 2-mandatory/5-writing-tests.js | 39 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/2-mandatory/5-writing-tests.js b/2-mandatory/5-writing-tests.js index 1443608b..61ef57b2 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,46 @@ 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", () => { /* Remove the .skip above, then write the test body. */ + let number = 71; + expect(convertScoreToGrade(number)).toEqual("B"); }); /* Write a test that checks a score of 68 is grade C */ +test("a score of 68 is grade C", () => { + let number = 68; + expect(convertScoreToGrade(number)).toEqual("C"); +}); /* Write a test that checks a score of 55 is grade D */ +test("a score of 55 is grade D", () => { + let number = 55; + expect(convertScoreToGrade(number)).toEqual("D"); +}); -/* - Write a test that checks a score of 68 is grade C -*/ - -/* - Write a test that checks a score of 55 is grade D -*/ - -/* - Write a test that checks a score of 49 is grade E -*/ +/* Write a test that checks a score of 49 is grade E + */ +test("a score of 49 is grade E", () => { + let number = 49; + expect(convertScoreToGrade(number)).toEqual("E"); +}); /* Write a test that checks a score of 30 is grade E */ +test("a score of 30 is grade E", () => { + let number = 30; + expect(convertScoreToGrade(number)).toEqual("E"); +}); /* Write a test that checks a score of 70 is grade B */ +test("a score of 70 is grade B", () => { + let number = 70; + expect(convertScoreToGrade(number)).toEqual("B"); +}); From 894487c30956f4e76a28fd58efa6f1f059e5e8da Mon Sep 17 00:00:00 2001 From: Appolin Semegni Fotso <108607571+AppolinFotso@users.noreply.github.com> Date: Sun, 19 Mar 2023 18:18:39 +0000 Subject: [PATCH 6/6] Mandatory-writing-test-advanced --- 2-mandatory/6-writing-tests-advanced.js | 101 ++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index 8d227e27..1aa40da6 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) { @@ -29,17 +29,55 @@ function convertScoreToGrade() { } function formatCourseworkResult(trainee) { - if (!trainee.name) { - return "Error: No trainee name!"; - } let traineeName = trainee.name; - if (typeof trainee.score != "number") { - return "Error: Coursework percent is not a number!"; - } let traineeGrade = convertScoreToGrade(trainee.score); - return `${traineeName}'s coursework was marked as grade ${traineeGrade}.`; + /* Added */ + let traineeAge = trainee.age; + + /* Added */ + let traineeSubjects = trainee.subjects; + + /* First condition*/ + if (trainee.age == undefined && trainee.subjects == undefined) { + if (!trainee.name) { + return "Error: No trainee name!"; + } + if (typeof trainee.score != "number") { + return "Error: Coursework percent is not a number!"; + } + return `${traineeName}'s coursework was marked as grade ${traineeGrade}.`; + } + + /* Second condition*/ + if (trainee.name == undefined && trainee.subjects == undefined) { + if (typeof trainee.age != "number") { + return "Error: Age is not a number!"; + } + if (typeof trainee.score != "number") { + return "Error: Coursework percent is not a number!"; + } + return `A student with the age of ${traineeAge} was marked as grade ${traineeGrade}.`; + } + + /* Third condition*/ + if (trainee.score == undefined && trainee.age == undefined) { + if (!Array.isArray(trainee.subjects)) { + return "Error: Not a subject list!"; + } + if (!trainee.name) { + return "Error: No trainee name!"; + } + return `${traineeName} completed the following subjects: ${traineeSubjects.join( + ", " + )}.`; + } + + /* All properties available in the object*/ + return `Name: ${traineeName}, Age: ${traineeAge}, Subjects: ${traineeSubjects.join( + ", " + )}, Grade: ${traineeGrade}.`; } /* ======= TESTS - FOR THIS EXERCISE YOU SHOULD MODIFY THEM! ===== @@ -55,6 +93,15 @@ function formatCourseworkResult(trainee) { score: 63 } */ +test("checking trainee name and grade with a score of 63", () => { + const student = { + name: "Xin", + score: 63, + }; + expect(formatCourseworkResult(student)).toEqual( + "Xin's coursework was marked as grade C." + ); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -63,6 +110,15 @@ function formatCourseworkResult(trainee) { score: 78 } */ +test("checking trainee name and grade with a score of 78", () => { + const student = { + name: "Mona", + score: 78, + }; + expect(formatCourseworkResult(student)).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 +129,17 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ +test("checking trainee name, age, subjects and grade with a score of 78", () => { + const student = { + name: "Ali", + score: 49, + age: 33, + subjects: ["JavaScript", "React", "CSS"], + }; + expect(formatCourseworkResult(student)).toEqual( + "Name: Ali, Age: 33, Subjects: JavaScript, React, CSS, Grade: E." + ); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -81,6 +148,15 @@ function formatCourseworkResult(trainee) { age: 29 } */ +test("checking trainee age and grade with a score of 90", () => { + const student = { + score: 90, + age: 29, + }; + expect(formatCourseworkResult(student)).toEqual( + "A student with the age of 29 was marked as grade A." + ); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -89,3 +165,12 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test("checking trainee name and subjects", () => { + const student = { + name: "Aman", + subjects: ["HTML", "CSS", "Databases"], + }; + expect(formatCourseworkResult(student)).toEqual( + "Aman completed the following subjects: HTML, CSS, Databases." + ); +});