From ba7151c117d9b19aaa64974e8fbef111748bd8b4 Mon Sep 17 00:00:00 2001 From: anuthapaliy <113211321+anuthapaliy@users.noreply.github.com> Date: Tue, 21 Mar 2023 11:41:04 +0000 Subject: [PATCH 1/4] exer B not done yet --- 1-exercises/A-accessing-values/exercise1.js | 14 ++++---- 1-exercises/A-accessing-values/exercise2.js | 2 +- 1-exercises/A-accessing-values/exercise3.js | 4 ++- 2-mandatory/1-recipes.js | 36 ++++++++++++++++++++- 2-mandatory/2-currency-code-lookup.js | 9 ++++-- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..aae9d387 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -5,19 +5,19 @@ */ let dog = { - breed: "Dalmatian", - name: "Spot", - isHungry: true, - happiness: 6 + breed: "Dalmatian",//string + name: "Spot",//string + isHungry: true,//Boolean + happiness: 6//number }; /* - You can access the values of each property using dot notation. +You can access the values of each property using dot notation. Log the name and breed of this dog using dot notation. */ -let dogName; // complete the code -let dogBreed; // complete the code +let dogName = dog.name; +let dogBreed = dog.breed; console.log(`${dogName} is a ${dogBreed}`); diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..0285b1a2 100644 --- a/1-exercises/A-accessing-values/exercise2.js +++ b/1-exercises/A-accessing-values/exercise2.js @@ -17,7 +17,7 @@ let capitalCities = { */ let myCountry = "UnitedKingdom"; -let myCapitalCity; // complete the code +let myCapitalCity = "London"; console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..8c081a7e 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -21,7 +21,9 @@ let basketballTeam = { */ // write code here - +let topPlayers = ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"]; +topPlayers.sort(); +console.log(topPlayers); /* EXPECTED RESULT diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..f97b4bbc 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,38 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here +let receipe1= { + title: "Momo", + serving: 2, + ingredients: ["wheat", "kima", "wrapper"], +}; + console.log(receipe1) + +let receipe2 = { + title: "waiwai", + serving: 1, + ingredients: ["waiwai", "water", "masala"], +}; + console.log(receipe2); + +let receipe3 = { + title: "Omelette", + serving: 2, + ingredients: ["onion", "corrinder", "salt"], +}; + console.log(receipe3); + +let receipe4 = { + title: "chickencurry", + serving: 4, + ingredients: ["oil","onion","garlic", "ginger", "cumin", "corrinder", "tumeric"] +} + console.log(receipe4); + +let receipe5 = { + title: "pilourice", + serving: 5, + ingredients: ["rice", "cinamom", "cumin", "onion","cloves", "bayleaves", "water"], +}; + console.log(receipe5); \ 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..38b49863 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,8 +18,13 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here -} + let countryCurrencyCodesLookUp = {}; + for(countryCurrencyCode of countryCurrencyCodes){ + + + } + return countryCurrencyCodesLookUp; +}; /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` From e17694c72684620cd076c0b30e9607d227515077 Mon Sep 17 00:00:00 2001 From: anuthapaliy <113211321+anuthapaliy@users.noreply.github.com> Date: Sun, 26 Mar 2023 12:49:39 +0100 Subject: [PATCH 2/4] extra not completed yet --- 2-mandatory/2-currency-code-lookup.js | 15 +++++--- 2-mandatory/3-shopping-list.js | 27 +++++++++++--- 2-mandatory/4-restaurant.js | 40 +++++++++++++++++++-- 2-mandatory/5-writing-tests.js | 47 +++++++++++++++++-------- 2-mandatory/6-writing-tests-advanced.js | 34 +++++++++++++++--- 5 files changed, 132 insertions(+), 31 deletions(-) diff --git a/2-mandatory/2-currency-code-lookup.js b/2-mandatory/2-currency-code-lookup.js index 38b49863..e5e10b8b 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -17,14 +17,21 @@ const COUNTRY_CURRENCY_CODES = [ ["MX", "MXN"], ]; + + function createLookup(countryCurrencyCodes) { let countryCurrencyCodesLookUp = {}; - for(countryCurrencyCode of countryCurrencyCodes){ - + + for(let countryCurrencyCode of countryCurrencyCodes){ + countryCurrencyCodesLookUp[countryCurrencyCode[0]]=countryCurrencyCode[1]; } - return countryCurrencyCodesLookUp; -}; + + return countryCurrencyCodesLookUp; + }; + + + /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js` diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..e02ea89e 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -19,8 +19,25 @@ 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)=== false + && pantry.cupboardContents.includes(ingredient)=== false) { + + 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` @@ -43,11 +60,11 @@ 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", "chicken"] }); -}); \ No newline at end of file +}); diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..41c3c59c 100644 --- a/2-mandatory/4-restaurant.js +++ b/2-mandatory/4-restaurant.js @@ -20,8 +20,44 @@ 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; + } + } +}; + + // let coffeeMachine = { + // brand: "Super Coffee", + // prices: { + // cappuccino: 2.4, + // blackCoffee: 1.5, + // flatWhite: 3.0, + // }, + // insertedAmount: 0, + // insertMoney: function (amount) { + // this.insertedAmount += amount; // or this.insertedAmount = this.insertedAmount + amount; + // }, + // getCoffee: function (coffee) { + // if (this.insertedAmount >= this.prices[coffee]) { + // this.insertedAmount = 0; // insertedAmount resets after a transaction + // return `Please take your ${coffee}`; + // } else { + // return `Sorry you don't have enough money for a ${coffee}`; + // } + // }, + + + /* ======= 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..f9302192 100644 --- a/2-mandatory/5-writing-tests.js +++ b/2-mandatory/5-writing-tests.js @@ -34,8 +34,9 @@ function convertScoreToGrade(score) { The first test has been written for you. You need to fix the test so that it passes. */ + test("a score of 83 is grade A", () => { - expect(convertScoreToGrade(83), "Z"); + expect(convertScoreToGrade(83)).toEqual ("A"); }); /* @@ -43,33 +44,49 @@ 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. */ + + + // * Remove the .skip above, then write the test body. * + test("a score of 71 is grade B", () => { + expect(convertScoreToGrade(71)).toEqual ("B"); + }); -/* - 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 68 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 55 is grade D", () => { + expect(convertScoreToGrade(55)), ("D"); +}) /* Write a test that checks a score of 49 is grade E -*/ - +*/test("a score of 49 is grade E", () => { + expect(convertScoreToGrade(49)), ("E"); +}) /* Write a test that checks a score of 30 is grade E -*/ +*/test("a score of 30 is grade E", () => { + expect(convertScoreToGrade(30)), ("E"); +}) /* Write a test that checks a score of 70 is grade B -*/ +*/test("a score of 70 is grade B", () => { + expect(convertScoreToGrade(70)), ("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..caa1cd71 100644 --- a/2-mandatory/6-writing-tests-advanced.js +++ b/2-mandatory/6-writing-tests-advanced.js @@ -54,18 +54,26 @@ function formatCourseworkResult(trainee) { name: "Xin", score: 63 } -*/ - -/* +*/test("a score of 63 is grade C", () => { +const trainee = { name: "Xin", score: 63 }; + expect(formatCourseworkResult(trainee)).toEqual( + "Xin's coursework was marked as grade C." + ); +});/* Write a test that checks the output of formatCourseworkResult when passed the following trainee: { name: "Mona", score: 78 } -*/ +*/test("a score of 78 is grade B", () => { + let trainee = { name: "Mona", score: 78 }; + expect(formatCourseworkResult(trainee)). toEqual( + "Mona's coursework was marked as grade B." + ); +}); /* - Write a test that checks the output of formatCourseworkResult when passed the following trainee: + Write a test that checks the output of formatCourseworkResult when passed the following trainee: { name: "Ali", score: 49, @@ -73,6 +81,12 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ +test("a score of 49 is grade E", () => { + let trainee = {name:"Ali", score:49, age: 33, subjects:["JavaScript", "React", "CSS"]}; + expect(formatCourseworkResult(trainee)). toEqual( + "Ali's coursework was marked as grade E." + ); +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -81,6 +95,11 @@ function formatCourseworkResult(trainee) { age: 29 } */ +test("object without name will fail error", () => { + let trainee = {score: 90, age: 20}; + expect(formatCourseworkResult(trainee)). toEqual("Error: No trainee name!") + +}); /* Write a test that checks the output of formatCourseworkResult when passed the following trainee: @@ -89,3 +108,8 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test("object without score is not a number", () => { + let trainee ={name: "Aman", subjects:["HTML", "CSS", "Databases"]}; + expect(formatCourseworkResult(trainee)). toEqual("Error: Coursework percent is not a number!"); + +}); From 406353d7506680aefe1030ba26fd68cddc6f9c9f Mon Sep 17 00:00:00 2001 From: anuthapaliy <113211321+anuthapaliy@users.noreply.github.com> Date: Sun, 26 Mar 2023 13:09:44 +0100 Subject: [PATCH 3/4] sorted mandatory-6 --- 2-mandatory/6-writing-tests-advanced.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2-mandatory/6-writing-tests-advanced.js b/2-mandatory/6-writing-tests-advanced.js index caa1cd71..9b393b5e 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) { From 385ae57960ef2ff524ec5435bd78d699cd68050e Mon Sep 17 00:00:00 2001 From: anuthapaliy <113211321+anuthapaliy@users.noreply.github.com> Date: Mon, 27 Mar 2023 09:39:28 +0100 Subject: [PATCH 4/4] done except extra --- 2-mandatory/3-shopping-list.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index e02ea89e..4edae8f3 100644 --- a/2-mandatory/3-shopping-list.js +++ b/2-mandatory/3-shopping-list.js @@ -60,11 +60,11 @@ 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", "chicken"] + items: ["flour", "yeast", "mozarella"] }); });