Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Closed
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
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[myCountry]; // complete the code

console.log(myCapitalCity);

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

// write code here

console.log(basketballTeam.topPlayers.sort());

/* EXPECTED RESULT

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

// write code here

student["attendance"] = 90;


/*
- Write an "if" statement that changes the value of hasPassed to true
if the student has attendance that is equal or greater than 90
Expand All @@ -26,6 +29,9 @@ let student = {
*/

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

console.log(student);

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

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

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); // does not have a property firstName
}

let user = {
Expand All @@ -35,4 +35,4 @@ let myPet = {
},
};

console.log(myPet.getName());
console.log(myPet.getName()); //object needs a return statement
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 @@ -9,9 +9,12 @@

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

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

/* EXPECTED RESULT

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

// write code here
// write code here

let recipeCard1 = {
title: "Mole",
serves: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
}

console.log(recipeCard1);

let recipeCard2 = {
title: "Soup",
serves: 2,
ingredients: ["onion", "tomato", "cilantro", "carrot"]
}

console.log(recipeCard2);

let recipeCard3 = {
title: "Omelette",
serves: 2,
ingredients: ["eggs", "butter", "pepper", "salt", "cheese"]
}

console.log(recipeCard3);

let recipeCard4 = {
title: "Pizza",
serves: 2,
ingredients: ["flour", "tomato", "cheese", "chicken", "mushroom"]
}

console.log(recipeCard4);

let recipeCard5 = {
title: "Cake",
serves: 2,
ingredients: ["flour", "chocolate", "milk", "butter", "sugar"]
}

console.log(recipeCard5);

1 change: 1 addition & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
return Object.fromEntries(countryCurrencyCodes);
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
17 changes: 15 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -19,9 +19,22 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here

const allIngredients = Object.values(pantry).flat();
const missingItems = recipe.ingredients.filter((ingredient, index, array) => {
if (allIngredients.includes(ingredient)) {
return false;
}
return true;
});
const objectToReturn = {
name: recipe.name,
items: missingItems,
};
return objectToReturn;
}


/* ======= 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
18 changes: 16 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ 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