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
8 changes: 4 additions & 4 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
happiness: 6,
};

/*
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; // complete the code
let dogBreed = dog.breed; // complete the code

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

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
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
7 changes: 5 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ let basketballTeam = {
*/

// write code here

basketballTeam.topPlayers.sort();
for (let i = 0; i < basketballTeam.topPlayers.length; i++) {
console.log(basketballTeam.topPlayers[i]);
}

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
5 changes: 5 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -26,7 +26,9 @@ let student = {
*/

// write code here

if (student.attendance >= 90 && student.examScore > 60) {
student["hasPassed"] = true;
}
console.log(student);

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

console.log(car["colour"]);
console.log(car["colour"]); // There is no color property!

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}

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

sayHelloToUser(user);
sayHelloToUser(user); // There is no user firstName property.

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
getName: function () {
"My pet's name is Fluffy";
},
};

console.log(myPet.getName());
console.log(myPet.getName()); // There is no return function.
1 change: 1 addition & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

let student = {
// write code here
getName : (name) => console.log(`Student name: ${name}`)
}

student.getName("Daniel");
Expand Down
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 recipes = {
recipe1: {
title: "Pasta",
servings: 6,
ingredients: ["Pasta", "ketchub", "salt"],
},
recipe2: {
title: "Pizza",
servings: 4,
ingredients: ["mince", "tomato", "mushroom", "chese", "onion"],
},
recipe3: {
title: "manti",
serving: 4,
ingredients: [" dough", "minced meat", "tomato sauce", "yogurt"],
},
recipe4: {
title: "icli kofte",
serving: 8,
ingredients: ["fine wheat", "minced-meat", "vegetable oil", "spices"],
},
recipe5: {
title: "rice",
servings: 5,
ingredients: ["rice", "butter", "salt", "hot water"],
},
};
console.log("-------------Recipe 1 --------------------");
console.log(recipes.recipe1.title);
console.log("Servings: " + recipes.recipe1.servings);
console.log("Ingredients:");
for (let i = 0; i < recipes.recipe1.ingredients.length;i++){

console.log(recipes.recipe1.ingredients[i]);
}
console.log("-------------Recipe 2 --------------------");
console.log(recipes.recipe2.title);
console.log("Servings: " + recipes.recipe2.servings);
console.log("Ingredients:");
for (let i = 0; i < recipes.recipe2.ingredients.length; i++) {
console.log(recipes.recipe2.ingredients[i]);
}
console.log("-------------Recipe 3 --------------------");
console.log(recipes.recipe3.title);
console.log("Servings: " + recipes.recipe3.servings);
console.log("Ingredients:");
for (let i = 0; i < recipes.recipe3.ingredients.length; i++) {
console.log(recipes.recipe3.ingredients[i]);
}
console.log("-------------Recipe 4 --------------------");
console.log(recipes.recipe4.title);
console.log("Servings: " + recipes.recipe4.servings);
console.log("Ingredients:");
for (let i = 0; i < recipes.recipe4.ingredients.length; i++) {
console.log(recipes.recipe4.ingredients[i]);
}
console.log("-------------Recipe 5 --------------------");
console.log(recipes.recipe5.title);
console.log("Servings: " + recipes.recipe5.servings);
console.log("Ingredients:");
for (let i = 0; i < recipes.recipe5.ingredients.length; i++) {
console.log(recipes.recipe5.ingredients[i]);
}
5 changes: 4 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let createLookupObj = {};
countryCurrencyCodes.map((country) => createLookupObj[country[0]] = country[1]);
return createLookupObj;

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
20 changes: 16 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let obj = {};
obj.name = recipe.name;
obj.items = recipe.ingredients.filter( (e) =>{
return (!(pantry.fridgeContents.includes(e)) &&!(pantry.cupboardContents.includes(e)))
})
return obj;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -43,11 +48,18 @@ 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"],
});
});
});
16 changes: 14 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ const MENU = {
};

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