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

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

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

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

console.log(myCapitalCity);


/* EXPECTED RESULT

London
Expand Down
5 changes: 2 additions & 3 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ let basketballTeam = {
address: "1901 W Madison St",
},
};

/*
Write code that
- accesses the basketball team's top players array
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/

// write code here

let basketballTeamsTopPlayers = basketballTeam.topPlayers.sort().join("\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good idea to use a variable to make your code more readable

console.log(basketballTeamsTopPlayers);

/* EXPECTED RESULT

Expand Down
10 changes: 6 additions & 4 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ let capitalCities = {
name: "Beijing",
}
};

/*
Using dot notation:
- Change the value of UnitedKingdom's capital city population to 8980000.
- Add the property for population to China's capital city and set the value to 21500000.
- Add the property for population to China's capital city and
set the value to 21 500 000.
- Add the country "Peru" to capitalCities object.
- Add a name of "Lima" to Peru's capital city.
- Add a population of 9750000 to Peru's capital city.
*/

// write code here

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

/* EXPECTED RESULT
Expand Down
9 changes: 4 additions & 5 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@ 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
AND
exam score is above 60.
- 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);

/* EXPECTED RESULT

{
name: "Reshma Saujani",
examScore: 65,
hasPassed: true,
attendance: 90
}

*/
9 changes: 4 additions & 5 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ let car = {
brand: "Ford",
yearsOld: 8,
};

console.log(car["colour"]);
// In object car there is no property - "colour"

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

let user = {
name: "Mira"
};

sayHelloToUser(user);
// the property of object is only one and called "name", not "firstName"

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

console.log(myPet.getName());
// the getName is not a function , getName is property of object myPet
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's not correct: getName is a function, and myPet.getName() does call it. The reason why it outputs undefined is elsewhere. I didn't see it at first, either!

6 changes: 4 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

let student = {
// write code here
}

getName: function (name) {
console.log(`Student name: ${name}`);
}
};
student.getName("Daniel");

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

// write code here
// write code here
console.log("\ ")
// Recipe 1 Borshch
let recipe1 = {
title: "Borsch",
servings: 75,
ingredients: [
"Cabbage -5kg",
"Potato -5kg",
"Carrot -3kg",
"Onion -1kg",
"Beetroot -1kg",
"Bean-2kg",
"Tomatoes-2kg",
"Vegetable oil - 200g",
]
};
console.log("Recipe 1", " ", recipe1.title);
console.log("Servings: ", recipe1.servings);
console.log("Ingredients:", "\n", recipe1.ingredients.join("\n"));
console.log(`\ `);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure that line is necessary

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

or perhaps you meant console.log('\n') as a separator?


// Recipe 2 Pasta
let recipe2 = {
title: "Pasta",
servings: 2,
ingredients: ["Pasta -300g", "Butter -20g","Water -1000g"]
};
console.log("Recipe 2", " ", recipe2.title);
console.log("Servings: ", recipe2.servings);
console.log("Ingredients:", "\n", recipe2.ingredients.join("\n"));
console.log(`\ `);

// Recipe 3 Cake Kyiv
let recipe3 = {
title: "Cake Kyiv",
servings: 5,
ingredients: ["Nuts-100g", "Eggs-3", "Butter-20g", "Flour-500g", "Sugar-10g", "Milk-200g"],
};
console.log("Recipe 3", " ", recipe3.title);
console.log("Servings: ",recipe3.servings);
console.log("Ingredients:", "\n", recipe3.ingredients.join("\n"));
console.log(`\ `);

// Recipe 4 Potato
let recipe4 = {
title: "Potato",
servings: 15,
ingredients: ["Potato -5kg", "Butter -500g", "Water -10l"]
};
console.log("Recipe 4", " ", recipe4.title);
console.log("Servings: ", recipe4.servings);
console.log("Ingredients:", "\n", recipe4.ingredients.join("\n"));
console.log(`\ `);

// Recipe 5
let recipe5 = {
title: "Latte",
servings: 75,
ingredients: ["Coffee -10kg", "Milk -5kg", "Water -10l"]
};
console.log("Recipe 5", " ", recipe5.title);
console.log("Servings: ", recipe5.servings);
console.log("Ingredients:", "\n", recipe5.ingredients.join("\n"));
console.log(`\ `);
2 changes: 2 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
return Object.fromEntries(countryCurrencyCodes);
// The Object.fromEntries() static method transforms a list of key-value pairs into an object.
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
9 changes: 9 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
return {
name: recipe.name,
items: recipe.ingredients.filter(
(element) =>
pantry.fridgeContents.indexOf(element) === -1 &&
pantry.cupboardContents.indexOf(element) === -1
),
};
// --
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
15 changes: 14 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ const MENU = {

let cashRegister = {
// write code here
}
orderBurger: function (balance) {
if (balance - MENU.burger >= 0) {
balance -= MENU.burger;
}
return balance;
},
orderFalafel: function (balance) {
if (balance - MENU.falafel >= 0) {
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
11 changes: 10 additions & 1 deletion 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ function countWords(string) {
const wordCount = {};

// write code here

if (string.length) {
string
.split(" ")
.forEach((element) =>
wordCount.hasOwnProperty(element)
? (wordCount[element] += 1)
: (wordCount[element] = 1)
);
}
// --
return wordCount;
}

Expand Down