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["UnitedKingdom"]; // complete the code

console.log(myCapitalCity);

Expand Down
20 changes: 20 additions & 0 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ let basketballTeam = {
*/

// write code here
top1 = [
basketballTeam.topPlayers[2],
basketballTeam.topPlayers[0],
basketballTeam.topPlayers[1],
];

// let text = "";
// for (let i = 0; i < top1.length; i++) {
// text += basketballTeam.topPlayers[i];
// }

// let text2 = "";
// for (let i = 0; i < basketballTeam.topPlayers.length; i++) {
// text2 += basketballTeam.topPlayers[i];
// }
// // ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"],
// // console.log(basketballTeam.topPlayers[i]);
// console.log(text2);

console.log(top1[0]);
console.log(top1[1]);
console.log(top1[2]);
/* EXPECTED RESULT

Dennis Rodman
Expand Down
5 changes: 5 additions & 0 deletions 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; //step 1
capitalCities.China.population = 21500000; //ste2

capitalCities.Peru = {}; //step3
capitalCities.Peru.name = "Lima"; //step4
capitalCities.Peru.population = 9750000;
console.log(capitalCities);

/* EXPECTED RESULT
Expand Down
4 changes: 4 additions & 0 deletions 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,6 +27,9 @@ let student = {
*/

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

console.log(student);

Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let car = {
brand: "Ford",
yearsOld: 8,
};

// the object car doesn't have property called caller
console.log(car["colour"]);

// Example 2
Expand All @@ -24,7 +24,7 @@ function sayHelloToUser(user) {
let user = {
name: "Mira"
};

// The object user does't have property called firstName
sayHelloToUser(user);

// Example 3
Expand All @@ -34,5 +34,5 @@ let myPet = {
"My pet's name is Fluffy";
},
};

// The string inside the function is return or printed on the screen
console.log(myPet.getName());
5 changes: 4 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

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

student.getName("Daniel");

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

// write code here
// write code here
let recipe = {
title: "Mole",
servings: "Serves:" + 2,
ingredients: ["cinnamon", "cumin", "cocoa"],
};
console.log(recipe.title);
console.log(recipe.servings);

// array
console.log("Ingredients:");
console.log(`${recipe.ingredients[0]}`);
console.log(`${recipe.ingredients[1]}`);
console.log(`${recipe.ingredients[2]}`);
5 changes: 5 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,11 @@ const COUNTRY_CURRENCY_CODES = [

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

/* ======= TESTS - DO NOT MODIFY =====
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 shoppingIngredients = recipe.ingredients.filter((ingredient) => {
return (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
);
});
return {
name: recipe.name,
items: shoppingIngredients,
};
}

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

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

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