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,21 +5,21 @@
*/

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
console.log (dog.name) ;
console.log (dog.breed);

console.log(`${dogName} is a ${dogBreed}`);
console.log(`${dog.name} is a ${dogbreed}`);

/* EXPECTED RESULT

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
34 changes: 34 additions & 0 deletions 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,39 @@

You should write and log at least 5 recipes
*/
let recipe1 = {
x: "bread",
cups: 2,
isHungry: ["a", "b", "c",],
};
console.log(recipe1.cups);

let recipe2 = {
x: "butter",
cups: 1,
isHungry: ["a", "b", "c",],
};
console.log(recipe2.isHungry[2]);

let recipe3 = {
x: "milk",
cups: 4,
fruits: ["apple", "banana", "cherry",],
};
console.log(recipe3.x);

let recipe4 = {
x: "strawberry",
teaSpoons: 7,
people: ["a", "b", "c",],
};
console.log(recipe4.teaSpoons);

let recipe5 = {
x: "eggs",
cups: 0,
when: ["morning", "afternoon", "evening",],
};
console.log(recipe5.when[0]);

// write code here
2 changes: 1 addition & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const COUNTRY_CURRENCY_CODES = [
];

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

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
18 changes: 16 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

The createShoppingList function should return an object with two properties:
- "name" of the recipe, which is a string,
- "items", which is an arry of the missing ingredients that need to be on the shopping list
- "items", which is an array of the missing ingredients that need to be on the shopping list
*/

let pantry = {
Expand All @@ -19,7 +19,21 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
const missingItems = [];

recipe.ingredients.forEach((ingredient) => {
if (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
) {
missingItems.push(ingredient);
}
});

return {
name: recipe.name,
items: missingItems
};
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
34 changes: 32 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,38 @@ const MENU = {
};

let cashRegister = {
// write code here
}
balance: 0,

orderBurger: function(balance) {
const burgerPrice = MENU.burger;
if (balance >= burgerPrice) {
this.balance = balance - burgerPrice;
return this.balance;
} else {
return balance;
}
},
orderFalafel: function(balance) {
const falafelPrice = MENU.falafel;
if (balance >= falafelPrice) {
this.balance = balance - falafelPrice;
return this.balance;
} else {
return balance;
}
},
};

// currentBalance: 0,
// orderBurger: function(burgerPrice) {
// if (this.currentBalance - burgerPrice >= 0) {
// this.currentBalance -= burgerPrice;
// return this.currentBalance;
// } else {
// return "You don't have enough money in your card. Sorry mate.";
// }
// }
// }; this code didn't work completely but was interesting.

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