Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ 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; // complete the code
let dogBreed = dog.breed; // complete the code

console.log(`${dogName} is a ${dogBreed}`);

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let capitalCities = {
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code
let myCapitalCity = capitalCities[myCountry]; // complete the code

console.log(myCapitalCity);

Expand Down
5 changes: 4 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ let basketballTeam = {
*/

// write code here

basketballTeam.topPlayers.sort();
for (element of basketballTeam.topPlayers) {
console.log(element);
}

/* EXPECTED RESULT

Expand Down
10 changes: 8 additions & 2 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ let capitalCities = {
- Add the country "Peru" to capitalCities object.
- Add a name of "Lima" to Peru's capital city.
- Add a population of 9750000 to Peru's capital city.
*/
*/

// write code here

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities["Peru"] = {
name:"Lima",
population: 9750000
}
console.log(capitalCities);

/* EXPECTED RESULT
Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let student = {
*/

// write code here
student["Attendance"] = 90;

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand All @@ -25,7 +26,12 @@ let student = {
- Use bracket notation to change the value of hasPassed
*/

// const result2 = 10 > 100 ? 'yes' : 'no';
// console.log(result2); // 👉️ 'no'

// write code here
let result = student.Attendance >= 90 && student.examScore > 60 ? student["hasPassed"] = true : student["hasPassed"] = false;
console.log(result);

console.log(student);

Expand Down
5 changes: 4 additions & 1 deletion 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]);
//colour is not assigned to the car object

// Example 2
function sayHelloToUser(user) {
Expand All @@ -26,6 +27,7 @@ let user = {
};

sayHelloToUser(user);
// user's first name is not defined

// Example 3
let myPet = {
Expand All @@ -36,3 +38,4 @@ let myPet = {
};

console.log(myPet.getName());
// The function has no return value
5 changes: 4 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
*/

let student = {
// write code here
getName : function(name) {
return `Student name: ${name}`
}// write code here
}
console.log(student.getName("Daniel"));

student.getName("Daniel");

Expand Down
60 changes: 59 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,62 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here
let Recipe1 = {
Title: "Waina",
Serves: 2,
Ingredients: [
"rice",
"water",
"yeast",
"miyan taushe",
"meat",
"oil"
],
};
let Recipe2 = {
Title: "Pounded Yam",
Serves: 1,
Ingredients: [
"Yam or Yam flour",
"water",
"Egusi soup"
],
};
let Recipe3 = {
Title: "Coated Yam",
Serves: 1,
Ingredients: [
"Yam",
"Eggs",
"oil",
"salt",
],
};
let Recipe4 = {
Title: "Peppered Fish",
Serves: 1,
Ingredients: ["Fish", "chilli pepper", "oil", "vegetables", "spices"],
};
let Recipe5 = {
Title: "Puff Puff",
Serves: 2,
Ingredients: [
"whole flour",
"milk",
"sugar",
"water",
"oil"
],
};

function favoriteRecipe(obj) {
for ([key, value] of Object.entries(obj)) {
console.log(`${key}: ${value}`);
}
}
favoriteRecipe(Recipe1);
favoriteRecipe(Recipe2);
favoriteRecipe(Recipe3);
favoriteRecipe(Recipe4);
favoriteRecipe(Recipe5);
11 changes: 11 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Hint: you'll need to use bracket notation to add new key/value pairs to the object
*/



const COUNTRY_CURRENCY_CODES = [
["GB", "GBP"],
["DE", "EUR"],
Expand All @@ -19,6 +21,15 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
let newObject = {};
for (element of countryCurrencyCodes) {
let country = element[0];
let currency = element[1];
newObject[country] = currency;

}

return newObject;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 11 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
let shoppingList = {};
shoppingList.name = recipe.name;
shoppingList.items = [];
recipe.ingredients.map((item) => {
if (
!pantry.fridgeContents.includes(item) &&
!pantry.cupboardContents.includes(item)
)
shoppingList.items.push(item);
});
return shoppingList;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
16 changes: 15 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ 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 =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down