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
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 = ("Spot")
let dogBreed = ("Dalmatian")

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

Expand Down
4 changes: 2 additions & 2 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,7 +17,7 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

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

// write code here

basketballTeam.topPlayers.sort().forEach((player) => {
console.log(player);
});

/* EXPECTED RESULT

Expand Down
4 changes: 4 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ let capitalCities = {

// 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: 4 additions & 2 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,9 +27,10 @@ let student = {
*/

// write code here

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

/* EXPECTED RESULT

{
Expand Down
5 changes: 3 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ console.log(car["colour"]);

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`);
// "user" object doesn't have a first Name defined
}

let user = {
Expand All @@ -32,7 +33,7 @@ let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
},
}, //a return statement is missing in getName
};

console.log(myPet.getName());
6 changes: 6 additions & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ let student = {
// write code here
}

getName: function (name) {
this.name = name;
console.log(`Student name: ${name}`);
},


student.getName("Daniel");

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

// write code here
// write code here

let recipe = {
title: "orange juice",
servings: 4,
ingredients: ["oranges", "ice cubes", "sugar", "water"],
};

console.log(recipe.title);
console.log(`Serves: ${recipe.servings}`);
console.log("Ingredients:");
recipe.ingredients.forEach((ingredient) => console.log(ingredient));

let recipe2 = {
title: "Pancakes",
servings: 3,
ingredients: ["flour", "eggs", "sugar", "butter"],
};

console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log("Ingredients:");
recipe2.ingredients.forEach((ingredient) => console.log(ingredient));

let recipe3 = {
title: "Jellofrice",
servings: 4,
ingredients: ["rice", "tomatoes", "vegetable-oil", "salt", "pepper"],
};

console.log(recipe3.title);
console.log(`Serves: ${recipe3.servings}`);
console.log("Ingredients:");
recipe3.ingredients.forEach((ingredient) => console.log(ingredient));

let recipe4 = {
title: "Noodles",
servings: 2,
ingredients: ["noodles", "carrots", "water"],
};

console.log(recipe4.title);
console.log(`Serves: ${recipe4.servings}`);
console.log("Ingredients:");
recipe4.ingredients.forEach((ingredient) => console.log(ingredient));

let recipe5 = {
title: "Pasta",
servings: 1,
ingredients: ["spaghetti", "tomatoes", "salt", "vegetable-oil", "thyme"],
};
console.log(recipe5.title);
console.log(`Serves: ${recipe5.servings}`);
console.log("Ingredients:");
recipe5.ingredients.forEach((ingredient) => console.log(ingredient));
8 changes: 8 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ const COUNTRY_CURRENCY_CODES = [

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

console.table(createLookup(COUNTRY_CURRENCY_CODES))




// console.log(createLookup(COUNTRY_CURRENCY_CODES));

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
23 changes: 20 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/*
You have a pantry object that tells you the contents of your fridge and your cupboards.

Write a function createShoppingList that takes a recipe as a parameter.
The recipe parameter has two properties:
- "name", which is a string
- "ingredients", which is an array of strings

The createShoppingList function should find which ingredients from the recipe are missing from the pantry.

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
Expand All @@ -20,7 +17,27 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
let res = {
name: recipe.name,
items: recipe.ingredients.filter(
(x) => !pantry.fridgeContents.concat(pantry.cupboardContents).includes(x)
),
};
return res;
}
console.log(
createShoppingList({
name: "margherita pizza",
ingredients: [
"flour",
"salt",
"yeast",
"tinned tomatoes",
"oregano",
"mozarella",
],
})
);

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
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 balance - MENU.burger
}
return balance;
},
orderFalafel: function (balance) {
if (balance >= MENU.falafel) {
return balance - MENU.falafel
}
return balance;
}
}

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