diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..038a0c2b 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -5,19 +5,18 @@ */ 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. 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..92775473 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"; // complete the code console.log(myCapitalCity); diff --git a/1-exercises/A-accessing-values/exercise3.js b/1-exercises/A-accessing-values/exercise3.js index 2e160dd5..8767315c 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -19,6 +19,7 @@ let basketballTeam = { - sorts the top players in alphabetical order - console.logs the name of each player on a new line */ +basketballTeam.topPlayers.sort().forEach(element=> console.log(element)) // write code here diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..88c3ffc2 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -10,7 +10,7 @@ let capitalCities = { }, China: { name: "Beijing", - } + }, }; /* @@ -23,6 +23,11 @@ let capitalCities = { */ // write code here +capitalCities.UnitedKingdom.population=8980000; +capitalCities.China.population=21500000; +capitalCities.Peru={}; +capitalCities.Peru.name="Lima"; +capitalCities.Peru.population=9750000; console.log(capitalCities); diff --git a/1-exercises/B-setting-values/exercise2.js b/1-exercises/B-setting-values/exercise2.js index 59fb7c1e..7b53cbdc 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -14,7 +14,7 @@ let student = { - Add a property to the student object for attendance - Set the value of attendance to 90 */ - +student["attendance"]=90; // write code here /* @@ -24,7 +24,7 @@ let student = { exam score is above 60. - Use bracket notation to change the value of hasPassed */ - +if(student.attendance>=90 && student.examScore>60){student["hasPassed"]=true;} // write code here console.log(student); diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..f7f682bc 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -14,11 +14,11 @@ let car = { yearsOld: 8, }; -console.log(car["colour"]); +console.log(car["colour"]);//there is not colour property in the car object // Example 2 function sayHelloToUser(user) { - console.log(`Hello ${user.firstName}`); + console.log(`Hello ${user.firstName}`);//there is name not firstName } let user = { @@ -32,7 +32,10 @@ let myPet = { animal: "Cat", getName: function() { "My pet's name is Fluffy"; + // return myPet }, + }; console.log(myPet.getName()); +//the function does not have return diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..14eb695a 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -9,6 +9,9 @@ let student = { // write code here + getName:function(name){ + console.log(`student name:${name}`) + } } student.getName("Daniel"); diff --git a/2-mandatory/1-recipes.js b/2-mandatory/1-recipes.js index 6243fa9c..10c720b8 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -22,4 +22,35 @@ You should write and log at least 5 recipes */ -// write code here \ No newline at end of file +// write code here + +let recipes = [ + { title: "Mole", serves: 2, ingredients: ["cinnamon", "cumin", "cocoa"] }, + { title: "Rice", serves: 5, ingredients: ["rice", "water", "oil"] }, + { + title: "pizza", + serves: 3, + ingredients: ["flour", "onions", "meat", "garlic"], + }, + { + title: "curry", + serves: 6, + ingredients: ["chicken", "onions", "mushrooms"], + }, + { + title: "soup", + serves: 1, + ingredients: ["water", "flour", "peas", "mushroom"], + }, +]; + +for (let i=0; i= 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..381313bc 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,54 @@ 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. */ }); + +test("a score of 68 is grade C", () => { + expect(convertScoreToGrade(68)).toBe("C"); +}); + /* 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 C", () => { + 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..c5eb3334 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,7 +55,16 @@ function formatCourseworkResult(trainee) { score: 63 } */ +test("Xin score of 63 is grade C", () => { + let 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: { @@ -63,7 +72,16 @@ function formatCourseworkResult(trainee) { score: 78 } */ +test("Mona 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: { @@ -73,7 +91,18 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ - +test("Ali 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,11 +110,27 @@ function formatCourseworkResult(trainee) { age: 29 } */ - +test("No trainee 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: { name: "Aman", subjects: ["HTML", "CSS", "Databases"] } -*/ +*/test("No trainee score", () => { + let trainee = { + name: "Aman", + subjects: ["HTML", "CSS", "Databases"] + } +expect(formatCourseworkResult(trainee)).toEqual( + "Error: Coursework percent is not a number!" +) +})