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
15 changes: 7 additions & 8 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
*/

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

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

console.log(`${dog.name} is a ${dog.breed}`);

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
6 changes: 3 additions & 3 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let capitalCities = {
UnitedKingdom: "London",
China: "Beijing",
Peru: "Lima"
Peru: "Lima",
};

/*
Expand All @@ -17,12 +17,12 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

/* EXPECTED RESULT

London

*/
*/
7 changes: 4 additions & 3 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ let basketballTeam = {
- console.logs the name of each player on a new line
*/

// write code here

console.log(basketballTeam.topPlayers[2]);
console.log(basketballTeam.topPlayers[0]);
console.log(basketballTeam.topPlayers[1]);

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
10 changes: 7 additions & 3 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
},
};

/*
Expand All @@ -22,7 +22,11 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.peru = {};
capitalCities.peru.name = "Lima";
capitalCities.peru.population = 9750000;

console.log(capitalCities);

Expand All @@ -34,4 +38,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

*/
*/
11 changes: 6 additions & 5 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let student = {
name: "Reshma Saujani",
examScore: 65,
hasPassed: false
hasPassed: false,
};

/*
Expand All @@ -15,7 +15,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
Expand All @@ -25,8 +25,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
Expand All @@ -38,4 +39,4 @@ console.log(student);
attendance: 90
}

*/
*/
10 changes: 7 additions & 3 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,30 @@
let car = {
brand: "Ford",
yearsOld: 8,
// We do not have a property called colour to the car object ex.. colour:"red"
};

console.log(car["colour"]);

// Example 2

function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}
// We do not have a property called firstName to the user object we can chang it to console.log(`Hello ${user.name}`);

let user = {
name: "Mira"
name: "Mira",
};

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
getName: function () {
return "My pet's name is Fluffy";
// we do noy have return here. the answer should be return("My pet's name is Fluffy");
},
};

Expand Down
8 changes: 5 additions & 3 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
*/

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

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

// write code here
// write code here

let favoriteRecipe = {
RecipeOne: {
title: "Rice",
Serves: 2,
Ingredients: ["water", "chicken", "oil", "salt", "tomato", "onion"],
},

RecipeTow: {
title: "PIZZAS",
Serves: 4,
Ingredients: ["flours", "salt", "oil", "Milk"],
},
RecipeThree: {
title: "pie",
Serves: 6,
Ingredients: ["flours", "oil", "onions", "leaves"],
},
RecipeFour: {
title: "tomato soup",
Serves: 8,
Ingredients: ["onion", "salt", "garlic", "chilli"],
},
RecipeFive: {
title: "Pasta",
Serves: 10,
Ingredients: ["water", "crème", "oil", "black pepper"],
},
};
// 1

console.log(favoriteRecipe.RecipeOne.title);
console.log(`Serves:${favoriteRecipe.RecipeOne.Serves}`);
console.log("Ingredients:");
favoriteRecipe.RecipeOne.Ingredients.forEach((a) => console.log(a));

// 2
console.log("//////////////////////////////////");
console.log(favoriteRecipe.RecipeTow.title);
console.log(`Serves:${favoriteRecipe.RecipeTow.Serves}`);
console.log("Ingredients:");
favoriteRecipe.RecipeTow.Ingredients.forEach((a) => console.log(a));

// 3
console.log("//////////////////////////////////");
console.log(favoriteRecipe.RecipeThree.title);
console.log(`Serves:${favoriteRecipe.RecipeThree.Serves}`);
console.log("Ingredients:");
favoriteRecipe.RecipeThree.Ingredients.forEach((a) => console.log(a));

// 4
console.log("//////////////////////////////////");
console.log(favoriteRecipe.RecipeFour.title);
console.log(`Serves:${favoriteRecipe.RecipeFour.Serves}`);
console.log("Ingredients:");
favoriteRecipe.RecipeFour.Ingredients.forEach((a) => console.log(a));

// 5
console.log("//////////////////////////////////");
console.log(favoriteRecipe.RecipeFive.title);
console.log(`Serves:${favoriteRecipe.RecipeFive.Serves}`);

console.log("Ingredients:");
favoriteRecipe.RecipeFive.Ingredients.forEach((a) => console.log(a));
8 changes: 7 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
return (countryCode = {
["GB"]: "GBP",
["DE"]: "EUR",
["NG"]: "NGN",
["MX"]: "MXN",
});
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +40,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
33 changes: 27 additions & 6 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let result = {
name: recipe.name,
items: [],
};

for (const ingredient of recipe.ingredients) {
if (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
) {
result.items.push(ingredient);
}
}

return result;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -31,23 +45,30 @@ function createShoppingList(recipe) {
test("createShoppingList works for pancakes recipe", () => {
let recipe1 = {
name: "pancakes",
ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"],
ingredients: ["flour", "salt", "milk", "mozarella", "vegetable oil"],
};

expect(createShoppingList(recipe1)).toEqual({
name: "pancakes",
items: ["flour", "eggs", "vegetable oil"],
items: ["flour", "mozarella", "vegetable oil"],
});
});

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"],
});
});
});
15 changes: 13 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ const MENU = {
};

let cashRegister = {
// write code here
}
orderBurger: function (balance) {
if (balance >= MENU.burger) {
balance = balance - MENU.burger;
}
return balance;
},
orderFalafel: function (balance) {
if (balance >= MENU.falafel) {
balance = balance - MENU.falafel;
}
return balance;
},
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
Loading