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

*/
*/
6 changes: 4 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,14 @@ let basketballTeam = {
*/

// write code here

for (let player of basketballTeam.topPlayers.sort()) {
console.log(player);
}

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
11 changes: 9 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,13 @@ 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 All @@ -34,4 +41,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

*/
*/
9 changes: 7 additions & 2 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 @@ -17,6 +17,8 @@ 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 +28,9 @@ let student = {
*/

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

console.log(student);

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

*/
*/
7 changes: 5 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ let car = {
};

console.log(car["colour"]);
// there is no property called 'colour' in the car object

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

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

sayHelloToUser(user);
// there is no property called 'firstName' in the user object

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

console.log(myPet.getName());
// nothing is being returned in the method definition of the 'getName' method
7 changes: 5 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

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

// write code here
// write code here
const recipe1 = {
title: "Fried Egg",
servings: 1,
ingredients: ["Egg", "Oil"],
};

console.log(recipe1.title);
console.log(`Serves: ${recipe1.servings}`);
console.log(`Ingredients:
${recipe1.ingredients[0]}
${recipe1.ingredients[1]}`);

const recipe2 = {
title: "Spinach Rice",
servings: 2,
ingredients: ["Spinach", "Rice"],
};

console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log(`Ingredients:
${recipe2.ingredients[0]}
${recipe2.ingredients[1]}`);

const recipe3 = {
title: "Behari Kebab",
servings: 4,
ingredients: ["Kebab", "Masala"],
};

console.log(recipe3.title);
console.log(`Serves: ${recipe3.servings}`);
console.log(`Ingredients:
${recipe3.ingredients[0]}
${recipe3.ingredients[1]}`);

const recipe4 = {
title: "Fried Fish",
servings: 1,
ingredients: ["Fish", "Oil"],
};

console.log(recipe4.title);
console.log(`Serves: ${recipe4.servings}`);
console.log(`Ingredients:
${recipe4.ingredients[0]}
${recipe4.ingredients[1]}`);

const recipe5 = {
title: "Icecream Milkshake",
servings: 1,
ingredients: ["Icecream", "Milk"],
};

console.log(recipe5.title);
console.log(`Serves: ${recipe5.servings}`);
console.log(`Ingredients:
${recipe5.ingredients[0]}
${recipe5.ingredients[1]}`);
Copy link
Copy Markdown

@IanTaiteCYF IanTaiteCYF Oct 10, 2022

Choose a reason for hiding this comment

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

Maybe you could have added a couple of helper functions to this exercise. One function to print a recipe and another to loop through an array of recipes printing each one.

12 changes: 10 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
const obj = {};

for (let pair of countryCurrencyCodes) {
obj[pair[0]] = pair[1];
}

return obj;
}

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 All @@ -34,4 +42,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
29 changes: 25 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
const newIngredientsList = [];

for (let ingredient of recipe.ingredients) {
if (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
) {
newIngredientsList.push(ingredient);
}
}

delete recipe.ingredients;
recipe.items = newIngredientsList;

return recipe;
}

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

let cashRegister = {
// write code here
}
orderBurger(balance) {
return balance >= MENU.burger ? balance - MENU.burger : balance;
},
orderFalafel(balance) {
return balance >= MENU.falafel ? balance - MENU.falafel : balance;
},
};

console.log(cashRegister.orderBurger(6.5));
console.log(cashRegister.orderBurger(6.49));

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
Loading