diff --git a/1-exercises/A-accessing-values/exercise1.js b/1-exercises/A-accessing-values/exercise1.js index 67416c69..79029801 100644 --- a/1-exercises/A-accessing-values/exercise1.js +++ b/1-exercises/A-accessing-values/exercise1.js @@ -16,11 +16,13 @@ let dog = { 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}`); + + /* EXPECTED RESULT Spot is a Dalmatian diff --git a/1-exercises/A-accessing-values/exercise2.js b/1-exercises/A-accessing-values/exercise2.js index 5b523ace..860288b7 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..97fa85a9 100644 --- a/1-exercises/A-accessing-values/exercise3.js +++ b/1-exercises/A-accessing-values/exercise3.js @@ -12,7 +12,8 @@ let basketballTeam = { address: "1901 W Madison St", }, }; - +let sortTeam = basketballTeam.topPlayers.sort(); +sortTeam.forEach(player =>console.log(player)); /* Write code that - accesses the basketball team's top players array @@ -20,7 +21,6 @@ let basketballTeam = { - console.logs the name of each player on a new line */ -// write code here /* EXPECTED RESULT diff --git a/1-exercises/B-setting-values/exercise1.js b/1-exercises/B-setting-values/exercise1.js index 7d0b05c5..5499d85a 100644 --- a/1-exercises/B-setting-values/exercise1.js +++ b/1-exercises/B-setting-values/exercise1.js @@ -7,9 +7,14 @@ let capitalCities = { UnitedKingdom: { name: "London", population: 20, + }, China: { name: "Beijing", + }, + + Peru:{ + } }; @@ -22,7 +27,14 @@ let capitalCities = { - Add a population of 9750000 to Peru's capital city. */ -// write code here + capitalCities.UnitedKingdom.population= 8980000 + capitalCities.China.population=2150000 + + capitalCities.Peru= { +name : "Lima", +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..9ca83ef2 100644 --- a/1-exercises/B-setting-values/exercise2.js +++ b/1-exercises/B-setting-values/exercise2.js @@ -6,7 +6,8 @@ let student = { name: "Reshma Saujani", examScore: 65, - hasPassed: false + hasPassed: false, + }; /* @@ -15,7 +16,7 @@ let student = { - Set the value of attendance to 90 */ -// write code here +student['attendance']=90; /* - Write an "if" statement that changes the value of hasPassed to true @@ -25,8 +26,9 @@ let student = { - Use bracket notation to change the value of hasPassed */ -// write code here - +if(student.attendance >= 90 && student.examScore> 60 ){ + student['hasPassed']=true +} console.log(student); /* EXPECTED RESULT diff --git a/1-exercises/C-undefined-properties/exercise.js b/1-exercises/C-undefined-properties/exercise.js index 8b00f6ce..2c7db8c0 100644 --- a/1-exercises/C-undefined-properties/exercise.js +++ b/1-exercises/C-undefined-properties/exercise.js @@ -15,6 +15,7 @@ let car = { }; console.log(car["colour"]); +//as we did not diclre color for the car// // Example 2 function sayHelloToUser(user) { @@ -27,6 +28,8 @@ let user = { sayHelloToUser(user); +// as we have 'name' in our object and gave that value but we called 'firstName' in line 22 and they are not match + // Example 3 let myPet = { animal: "Cat", @@ -36,3 +39,4 @@ let myPet = { }; console.log(myPet.getName()); +// there is not return statement in our function// \ No newline at end of file diff --git a/1-exercises/D-object-methods/exercise.js b/1-exercises/D-object-methods/exercise.js index 0b57f2e1..0c0fe478 100644 --- a/1-exercises/D-object-methods/exercise.js +++ b/1-exercises/D-object-methods/exercise.js @@ -8,8 +8,11 @@ */ 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..be49f8ff 100644 --- a/2-mandatory/1-recipes.js +++ b/2-mandatory/1-recipes.js @@ -21,5 +21,17 @@ You should write and log at least 5 recipes */ +let favoriteRecipe ={ + title : 'Mole', + servings : 2 , + ingredients :['cinnamon' , 'cumin' , 'cocoa' ] +}; + +console.log(favoriteRecipe.title); +console.log(`Serves: ${favoriteRecipe.servings}`); +console.log('Ingredients:') +favoriteRecipe.ingredients.forEach((item) => { + console.log(item); +}); // write code here \ 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..ff19a814 100644 --- a/2-mandatory/2-currency-code-lookup.js +++ b/2-mandatory/2-currency-code-lookup.js @@ -18,7 +18,14 @@ const COUNTRY_CURRENCY_CODES = [ ]; function createLookup(countryCurrencyCodes) { - // write code here + let currencyCodeLook ={}; + +for (let countryCurrencyCode of countryCurrencyCodes){ + let countryCode = countryCurrencyCode[0]; + let countryCurrency = countryCurrencyCode[1]; +currencyCodeLook[countryCode]=countryCurrency; +}; +return currencyCodeLook; } /* ======= TESTS - DO NOT MODIFY ===== diff --git a/2-mandatory/3-shopping-list.js b/2-mandatory/3-shopping-list.js index d25cb366..9e55c8df 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,9 +19,18 @@ let pantry = { }; function createShoppingList(recipe) { - // write code here -} + let shoppingList = recipe.ingredients.filter( + (ingredient) => { + return !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient) + + } + ); + return { + name : recipe.name, + items : shoppingList, + } +} /* ======= TESTS - DO NOT MODIFY ===== - To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js` - To run all exercises/tests in the mandatory folder, run `npm test` diff --git a/2-mandatory/4-restaurant.js b/2-mandatory/4-restaurant.js index d7b81eea..75809016 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){ + let lastBalance = balance; + let balanceEnough = balance - MENU.burger >= 0; + if (balanceEnough){ + lastBalance = balance - MENU.burger; + } + return lastBalance; + }, + orderFalafel : function (balance){ + let lastBalance = balance; + let balanceEnough = balance - MENU.falafel >= 0; + if (balanceEnough){ + lastBalance = balance - MENU.falafel; + } + return lastBalance; + }, +}; /* ======= 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..3531659d 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,48 @@ 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. */ -}); +test("a score of 71 is grade B", () => { + expect(convertScoreToGrade(71)).toBe ("B"); +}) /* 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..bb9c6d39 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,12 @@ function formatCourseworkResult(trainee) { 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: { @@ -63,7 +68,12 @@ function formatCourseworkResult(trainee) { score: 78 } */ - +test ('a score of 78 is grade B' , () => { + const 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 +83,17 @@ function formatCourseworkResult(trainee) { subjects: ["JavaScript", "React", "CSS"] } */ - +test('a score of 49 is grade E', () =>{ + const 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,7 +101,10 @@ function formatCourseworkResult(trainee) { age: 29 } */ - +test ('object without name property will face error' , () =>{ + const 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 +112,9 @@ function formatCourseworkResult(trainee) { subjects: ["HTML", "CSS", "Databases"] } */ +test('object without score property will face error' ,() => { + const trainee ={ name :'Amen' , subjects :['HTML' , ' CSS', 'Databases']}; + expect(formatCourseworkResult(trainee)).toEqual( + 'Error: Coursework percent is not a number!' + ); +});