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
14 changes: 7 additions & 7 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
*/

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}`);

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
8 changes: 4 additions & 4 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["UnitedKingdom"]; // complete the code

console.log(myCapitalCity);

// console.log(capitalCities["UnitedKingdom"]);
/* 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 topPlayersNames = basketballTeam.topPlayers
.sort()
.forEach((player) => console.log(player));


// console.log(topPlayersNames);
/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
13 changes: 10 additions & 3 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,7 +23,14 @@ let capitalCities = {
*/

// write code here

capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.Peru = {
name: "Lima",
population: 9750000,
};
// capitalCities.Peru.name = 'Lima';
// capitalCities.Peru.population = 9750000;
console.log(capitalCities);

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

*/
*/
9 changes: 6 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,7 +16,7 @@ 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 @@ -27,6 +27,9 @@ let student = {

// write code here

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

/* EXPECTED RESULT
Expand All @@ -38,4 +41,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,25 +14,25 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]); // There is color property which is not assigned.

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

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

sayHelloToUser(user);
sayHelloToUser(user); // The user object variable contains 'name,' while the function we are logging contains 'firstName.'

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

console.log(myPet.getName());
console.log(myPet.getName()); // The 'return' statement is missing from the function.
8 changes: 6 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,16 @@

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

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

// write code here
// write code here
let recipes = {
easyEggFriedRice: {
title: `Easy egg-fried rice`,
servings: 2,
ingerdiants: [
"250g long grain rice",
"3 tbsp vegetable oil",
"1 onion, finely chopped",
"4 eggs, beaten",
"2 spring onion, sliced, to serve",
" olive oil",
],
},
smokedMackerelRisotto: {
title: `Smoked mackerel risotto`,
servings: 3,
ingerdiants: [
"1 tbsp butter",
"1 onion, finely chopped",
"250 risotte rice",
"100ml white wine",
"1l begetable stock",
"1 x 240 pack smoked mackerel",
"2 spring onions, sliced",
"100g bag fresh spinach",
],
},
RoastLamb: {
title: `Roast lamb`,
servings: 8,
ingerdiants: [
"carrots",
"onion",
"small bunch parsley",
"thyme leaf",
"lemon",
],
},
Scampi: {
title: `Scampi with tartare sauce`,
servings: 2,
ingerdiants: [
"cornflour",
"sparkling water",
"beer",
"Dublin Bay prawn tails",
" olive oil",
],
},
};
function printOut(meals) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice job!

console.log(recipes[meals]["title"]);
console.log("Serves: " + recipes[meals]["servings"]);
console.log(
" Ingredients:" + recipes[meals]["ingerdiants"].map((x) => x + " \n ")
);
}

printOut("easyEggFriedRice");
printOut("smokedMackerelRisotto");
printOut("RoastLamb");
printOut("Scampi");
10 changes: 8 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let currencyObject = {};
for (let currency of countryCurrencyCodes) {
currencyObject[currency[0]] = currency[1];
}
return currencyObject;
// return Object.fromEntries(countryCurrencyCodes)
}
// console.log(COUNTRY_CURRENCY_CODES)

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand All @@ -34,4 +40,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
32 changes: 28 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,24 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let recipeName = recipe.name;
let recipeIngredients = recipe.ingredients;

let emptyContainer = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice solution. Can you think of a better name for this variable?


recipeIngredients.forEach((item) => {
if (
!pantry.fridgeContents.includes(item) &&
!pantry.cupboardContents.includes(item)
) {
emptyContainer.push(item);
}
});

return {
name: recipeName,
items: emptyContainer,
};
}

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

let cashRegister = {
// write code here
}
orderBurger: function (balance) {
if (balance >= MENU.burger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is excellent!

balance -= MENU.burger;
}
return balance;
},
orderFalafel: function (balance) {
if (balance >= MENU.falafel) {
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
Loading