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
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
2 changes: 2 additions & 0 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ let basketballTeam = {
*/

// write code here
let topPlayers=basketballTeam.topPlayers;
let alphabeticalOrder=basketballTeam.topPlayers.sort().map(e=>console.log(e));


/* EXPECTED RESULT
Expand Down
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 @@ -22,8 +22,13 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here

// write code
capitalCities.UnitedKingdom.population=8980000;
capitalCities.China.population=21500000;
capitalCities.Peru = new Object();
capitalCities.Peru.name = 'Lima';
capitalCities.Peru.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,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 @@ -26,6 +26,9 @@ let student = {
*/

// write code here
if(student.attendance>=90 && student.examScore>60){
student['hasPassed']='true' ;
}

console.log(student);

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

// Because car object doesnt have colour property.
console.log(car["colour"]);

// Example 2
// Because user object doesnt have firstName property it has name property
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}
Expand All @@ -28,11 +29,13 @@ let user = {
sayHelloToUser(user);

// Example 3
// Because we didnt call the function and this function doesnt return anything
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
},
};

console.log(myPet.getName());

console.log(myPet.getName());
4 changes: 4 additions & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

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


student.getName("Daniel");

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

// write code here
// write code here
let TeaRecipe = {
title: "Tea",
Service: 3,
ingredients: ["hot water", "tea", "sugar"],
};
const CookieRecipe = {
title: "Cookie",
Service: 3,
ingredients: ["sugar", "butter", "eggs", "sugar"],

};
const CakeRecipe = {
title: "Cake",
Service: 3,
ingredients: ["eggs", "oil", "milk", "sugar","flour"],

};
const RiceRecipe = {
title: "Rice",
Service: 2,
ingredients: ["rice", "salt", "hotwater", "butter"],

};
const SpagettieRecipe = {
title: "Spagettie",
Service: 2,
ingredients: ["spagettie", "tomatopaste", "water", "salt"],

};

const Menus = [
TeaRecipe,
CookieRecipe,
CakeRecipe,
RiceRecipe,
SpagettieRecipe,
];
Menus.map((menu) => {
console.log(menu.title);
console.log("Service: ", menu.Service);
console.log("ingredients: ");
for (const ingredient of menu.ingredients) {
console.log(ingredient);
}
});

14 changes: 13 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];



function createLookup(countryCurrencyCodes) {
// write code here
}

const newObject = {};
for (const something of countryCurrencyCodes) {
const newKey = something[0];
const newValue = something[1];
newObject[newKey] = newValue;
}
return newObject;
// return Object.fromEntries(countryCurrencyCodes);
}


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand Down
27 changes: 26 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,32 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
}

// allIngredients using .flat()
// const allIngredients = Object.values(pantry).flat();

// allIngredients using loops
// const allIngredients = [];
// Object.values(pantry).forEach((arrayOfValues) => {
// arrayOfValues.forEach((value) => allIngredients.push(value));
// });

// allIngredients using the ... (spread) operator (my preferred way)
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 =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand Down
19 changes: 18 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ const MENU = {

let cashRegister = {
// write code here
}

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

orderFalafel: (balance) => {
if (balance >= MENU.falafel) {
return balance - MENU.falafel;
} else {
return balance;
}
},
};


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