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

*/
*/
10 changes: 9 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ let basketballTeam = {
*/

// write code here
let b = basketballTeam.topPlayers;
b.sort();

b.forEach((b) => {
console.log(b);
});

// let topPlayers = basketballTeam.topPlayers;
// topPlayers.sort();
// topPlayers.map((player) => console.log(player));
/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

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

*/
*/
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"]); // we did,t define color in car object.

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); // we don't have .firstname property for user , we have .name .
}

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"; // Function defination isn't correct , } missing.
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not quite correct, undefined is returned because the function getName() does not return anything, it just defines a string.

};

Expand Down
9 changes: 6 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,16 @@
*/

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

*/
*/
39 changes: 38 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,42 @@

You should write and log at least 5 recipes
*/
let recipe1 = {
title: "Mole",
servings: 2,
ingredients: ["Cinnamon", "Cumin", "Cocoa"],
};

// write code here
let recipe2 = {
title: "Mashed Potato",
servings: 3,
ingredients: ["potato", "water"],
};

let recipe3 = {
title: "Brownie",
servings: 4,
ingredients: ["flour", "cocoa", "milk", "suger", "butter"],
};

let recipe4 = {
title: "Kale salad",
servings: 5,
ingredients: ["kale", "lettuce"],
};

let recipe5 = {
title: "energy booster",
servings: 3,
ingredients: ["ginger", "orange", "lime"],
};
console.log(recipe1.title);
console.log("Serving :", recipe1.servings);
console.log("Ingredients:", recipe1.ingredients);
// write code here
// let b = basketballTeam.topPlayers;
// b.sort();

// b.forEach((b) => {
// console.log(b);
// });
8 changes: 6 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,11 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let countryObj = {};
for (let i = 0; i < countryCurrencyCodes.length; i++) {
countryObj[countryCurrencyCodes[i][0]] = countryCurrencyCodes[i][1];
}
return countryObj;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +38,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
27 changes: 23 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
const allIngredients = [...pantry.fridgeContents, ...pantry.cupboardContents];

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

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

let cashRegister = {
// write code here
}

orderBurger: function (balance) {
let newBalance = balance;
if (balance >= MENU.burger) {
newBalance = balance - MENU.burger;
}
return newBalance;
},

orderFalafel: function (balance) {
let newBalance = balance;
if (balance >= MENU.falafel) {
newBalance = balance - MENU.falafel;
}
return newBalance;
},
};
/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down