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
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let dog = {
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}`);

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

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

// write code here

const names = basketballTeam.topPlayers.sort();
console.log(names.join(" "))

/* EXPECTED RESULT

Expand Down
7 changes: 6 additions & 1 deletion 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ 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
5 changes: 4 additions & 1 deletion 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,7 +27,9 @@ 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 @@ -15,12 +15,13 @@ let car = {
};

console.log(car["colour"]);
// In this example we get undefined because car doesn't have property "colour"

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

// Here a problem, because property name is 'name', not "FirstName"
let user = {
name: "Mira"
};
Expand All @@ -34,5 +35,5 @@ let myPet = {
"My pet's name is Fluffy";
},
};

// Here the problem in function, it doesn't work because it doesn't return anything
console.log(myPet.getName());
3 changes: 3 additions & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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

student.getName("Daniel");
Expand Down
36 changes: 35 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,38 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here

const recipe1 = {
title: "Easy kedgeree",
serves: 4,
ingredients: [
"300g basmati rice",
"600ml chicken stock",
"400g smoked haddock",
"100g frozen peas"
]
}
const recipe2 = {
title: "Mole",
serves: 2,
ingredients: [
"Cinnamon",
"Cumin",
"Cocoa"
]
}

const recipe3 = {
title: "Cacio e pepe",
serves: 2,
ingredients: [
"200g bucatini or spaghetti",
"25g butter",
"2 tsp whole black peppercorns, ground, or 1 tsp freshly ground black pepper",
"50g pecorino or parmesan, finely grated"
]
}
console.log(recipe1)
console.log(recipe2)
console.log(recipe3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: well done

6 changes: 6 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,14 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
const currencyCode = {};
for (let item of countryCurrencyCodes) {
currencyCode[item[0]] = item[1];
}
return currencyCode;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Well done!

Consider: You could also use .forEach https://www.w3schools.com/jsref/jsref_foreach.asp
function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
countryCurrencyCodes.forEach(([country, currency]) => {
lookup[country] = currency;
});
return lookup;
}

const lookup = createLookup(COUNTRY_CURRENCY_CODES);
console.log(lookup);



/* ======= 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
10 changes: 10 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
let missingIngredients = [];
recipe.ingredients.forEach((ingredient) => {
if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) {
missingIngredients.push(ingredient);
}
})
return {
name: recipe.name,
items: missingIngredients,
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Well done!


/* ======= TESTS - DO NOT MODIFY =====
Expand Down
6 changes: 6 additions & 0 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const MENU = {

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Well done!


/* ======= TESTS - DO NOT MODIFY =====
Expand Down
7 changes: 6 additions & 1 deletion 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@

function countWords(string) {
const wordCount = {};

const arr = string.split(" ");
for (let word of arr) {
if (word.length !== 0) {
wordCount[word] = (wordCount[word] || 0) + 1;
}
}
// write code here

return wordCount;
Expand Down