Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
12 changes: 6 additions & 6 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

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; // 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["UnitedKingdom"]; // complete the code

console.log(myCapitalCity);

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

// write code here
names = basketballTeam.topPlayers.sort()

console.log(names.join('\n'));

// names.forEach((player) => {
// console.log(player);
// });


/* EXPECTED RESULT
Expand Down
3 changes: 3 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,9 @@ let capitalCities = {
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000,
capitalCities.China.population = 21500000,
capitalCities.Peru = {name: "Lima", population: 9750000}

console.log(capitalCities);

Expand Down
4 changes: 4 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 @@ -26,6 +27,9 @@ let student = {
*/

// write code here
if (student["attendance"] >= 90 && student.examScore > 60) {
student.hasPassed = true
}

console.log(student);

Expand Down
11 changes: 7 additions & 4 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ let car = {
brand: "Ford",
yearsOld: 8,
};
// car.colour = "black", we need to define colour here.

console.log(car["colour"]);
console.log(car["colour"]); //we don't have a property called colour in the object so we get undefined.

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

let user = {
name: "Mira"
name: "Mira"
//firstName property does not exist
};

sayHelloToUser(user);

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

"My pet's name is Fluffy"; // we need to use the return key word statement
},
};

Expand Down
6 changes: 5 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

let student = {
// write code here
getName: function(name){

return `Student name: ${name} `
}
}

student.getName("Daniel");
console.log(student.getName("Daniel"));

/* EXPECTED RESULT

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

// write code here
// write code here

let favoriteRecipes = {
Title: "Chicken biryani",
Serves: 2,
Ingredients: ["chicken", "rice", "biryani masala"]
}


// Title: "spaghetti bolognese",
// Serves: 2,
// Ingredients: ["spaghetti", "olive oil", "onions"]
// },

// recipe5: {
// Title: "Chocalate cookies",
// Serves: 4,
// Ingredients: ["sugar", "butter", "flour", "eggs"]
// }



console.log(favoriteRecipes.Title);
console.log(`Serves: ${favoriteRecipes.Serves}`);
console.log(`Ingredients: ${favoriteRecipes.Ingredients}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(`Ingredients: ${favoriteRecipes.Ingredients}`);
console.log(`Ingredients: ${favoriteRecipes.Ingredients.split('\n')}`);


// console.log(favoriteRecipes.recipe2.Title);
// console.log(`Serves: ${favoriteRecipes.recipe2.Serves}`);
// console.log(`Ingredients: ${favoriteRecipes.recipe2.Ingredients}`);

// console.log(favoriteRecipes.recipe3.Title);
// console.log(`Serves: ${favoriteRecipes.recipe3.Serves}`);
// console.log(`Ingredients: ${favoriteRecipes.recipe3.Ingredients}`);

// console.log(favoriteRecipes.recipe4.Title);
// console.log(`Serves: ${favoriteRecipes.recipe4.Serves}`);
// console.log(`Ingredients: ${favoriteRecipes.recipe4.Ingredients}`);

// console.log(favoriteRecipes.recipe5.Title);
// console.log(`Serves: ${favoriteRecipes.recipe5.Serves}`);
// console.log(`Ingredients: ${favoriteRecipes.recipe5.Ingredients}`);

// console.log(favoriteRecipes.title);
// console.log(`Serves: ${favoriteRecipes.serves}`);
// console.log("Ingredients:")
// favoriteRecipes.Ingredients.forEach((ingredient) => {
// console.log(ingredient);
// });
5 changes: 5 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
let counCurrency = {};
countryCurrencyCodes.forEach(currency => {
counCurrency[currency[0]] = currency[1]
});
return counCurrency
}

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

function createShoppingList(recipe) {
// write code here
}

let missingItems = recipe.ingredients.filter((item)=> {

return !pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item)

});
return {
name : recipe.name,
items : missingItems,
Comment on lines +22 to +29
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let missingItems = recipe.ingredients.filter((item)=> {
return !pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item)
});
return {
name : recipe.name,
items : missingItems,
let missingItems = recipe.ingredients.filter((item)=> {
const isInFridge = pantry.fridgeContents.includes(item)
const isInCupboard = pantry.cupboardContents.includes(item)
return !isInFridge && !isInCupboard
});
return {
name : recipe.name,
items : missingItems,

};
};
/* ======= 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`
Expand Down
13 changes: 12 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ const MENU = {
};

let cashRegister = {
// write code here
orderBurger: function(balance){
if(balance >= MENU.burger){
return MENU.burger - balance
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return MENU.burger - balance
return balance - MENU.burger

}
return balance;
},
orderFalafel: function(balance){
if(balance >= MENU.falafel){
return MENU.falafel - balance
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return MENU.falafel - balance
return balance - MENU.falafel

}
return balance
}
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down