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

*/
*/
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[myCountry]; // complete the code

console.log(myCapitalCity);

/* EXPECTED RESULT

London

*/
*/
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

let topPlayersSorted = basketballTeam.topPlayers.sort();
for (item of topPlayersSorted) {
console.log(item);
}

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
10 changes: 8 additions & 2 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 @@ -24,6 +24,12 @@ 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);

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

*/
*/
8 changes: 5 additions & 3 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 @@ -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 @@ -25,7 +26,8 @@ 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);

Expand All @@ -38,4 +40,4 @@ console.log(student);
attendance: 90
}

*/
*/
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,24 +14,24 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]); // trying to log a property that does not exist in the object

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); // "firstName" should be "name" in this case
}

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

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
getName: function () {
("My pet's name is Fluffy"); // return "My pet's name is Fluffy" would be the correct way to end off this function. or console.log();
},
};

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

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

// write code here
function logRecipes(recipe) {
console.log(recipe.title);
console.log(`Serves: ${recipe.servings}`);
console.log(`Ingredients: ${recipe.ingredients}`);
}

let recipe1 = {
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"],
};

let recipe2 = {
title: "Semolina Pudding",
servings: 6,
ingredients: [
"3/4 cup Taystee wheat or Semolina",
"125gram + 25gram butter",
"2 pieces cinnamon stick",
"3 cups milk",
"1tspn elachie/cardamom powder",
"1 teaspoon almond powder",
"few strands saffron",
"few drops egg yellow food colouring",
"6-8 tbsp condensed milk",
"fresh cream",
],
};

let recipe3 = {
title: "Coffee",
servings: 1,
ingredients: [
"2 spoons of coffee",
"2 spoons of sugar",
"3-4 spoons coffee creamer",
],
};

let recipe4 = {
title: "Tea",
servings: 1,
ingredients: ["1 tea bag", "2 teaspoons of sugar", "milk"],
};

let recipe5 = {
title: "Banana loaf",
servings: 2,
ingredients: [
"butter",
"sugar",
"eggs",
"bananas",
"cake flour",
"salt",
"baking soda",
],
};

logRecipes(recipe1);

logRecipes(recipe2);

logRecipes(recipe3);

logRecipes(recipe4);

logRecipes(recipe5);
5 changes: 3 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
object = Object.assign(...countryCurrencyCodes.map(([k, v]) => ({ [k]: v }))); // source: https://tinyurl.com/3k5pjwch
return object;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +35,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
26 changes: 21 additions & 5 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,7 +19,16 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let result = recipe.ingredients.filter(
(element) =>
!pantry.fridgeContents.includes(element) &&
!pantry.cupboardContents.includes(element)
);
let finalList = {
name: recipe.name,
items: result,
};
return finalList;
}

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