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
10 changes: 5 additions & 5 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/*
This object has 4 properties
The properties of the object are all primitive types (string, number or boolean)
What is the type of each property?
What is the type of each property? string
*/

let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
happiness: 6,
};

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

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
6 changes: 3 additions & 3 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let capitalCities = {
UnitedKingdom: "London",
China: "Beijing",
Peru: "Lima"
Peru: "Lima",
};

/*
Expand All @@ -17,12 +17,12 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

/* EXPECTED RESULT

London

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

// write code here

console.log(basketballTeam.topPlayers)

/* 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 @@ -10,7 +10,7 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
},
};

/*
Expand All @@ -23,6 +23,11 @@ let capitalCities = {
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.Peru = {};
capitalCities.Peru.name = "Lima";
capitalCities.Peru.population = 9750000;

console.log(capitalCities);

Expand All @@ -34,4 +39,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

*/
*/
10 changes: 7 additions & 3 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let student = {
name: "Reshma Saujani",
examScore: 65,
hasPassed: false
hasPassed: false,
};

/*
Expand All @@ -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 @@ -27,6 +27,10 @@ let student = {

// write code here

if (student.attendance >= 90 && student.examScore > 60) {
student["hasPassed"] = true;
}

console.log(student);

/* EXPECTED RESULT
Expand All @@ -38,4 +42,4 @@ console.log(student);
attendance: 90
}

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

console.log(car["colour"]);
// car object doesn't have any colour key , so its undefined.

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

let user = {
name: "Mira"
name: "Mira",
};

// user object only has one property which is name, so firstName is undefined.
sayHelloToUser(user);

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

// there is no return in the function .
console.log(myPet.getName());
7 changes: 5 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

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

// write code here
// write code here
const recipes = {
first: {
title: "Spaghetti",
serves: 6,
ingredients: ["pasta", "mince", "tomato"],
},
second: {
title: "Hummus",
serves: 2,
ingredients: ["Tahini", "chickpea"],
},
third: {
title: "fish & chips",
serves: 4,
ingredients: ["fish", "potato", "bread crumbs"],
},
forth: {
title: "porridge",
serves: 1,
ingredients: ["oat", "milk"],
},
fifth: {
title: "guacamole",
serves: 3,
ingredients: ["avocado", "tomato", "onion", "parsley"],
Comment thread
AzinYad marked this conversation as resolved.
},
};

console.log(recipes.first.title);
console.log(`serves:${recipes.first.serves}`);
console.log(`ingredients:`);
console.log(recipes.first.ingredients[0]);
console.log(recipes.first.ingredients[1]);
console.log(recipes.first.ingredients[2]);

console.log(recipes.second.title);
console.log(`serves:${recipes.second.serves}`);
console.log(`ingredients:`);
console.log(recipes.second.ingredients[0]);
console.log(recipes.second.ingredients[1]);

console.log(recipes.third.title);
console.log(`serves:${recipes.third.serves}`);
console.log(`ingredients:`);
console.log(recipes.third.ingredients[0]);
console.log(recipes.third.ingredients[1]);
console.log(recipes.third.ingredients[2]);

console.log(recipes.forth.title);
console.log(`serves:${recipes.forth.serves}`);
console.log(`ingredients:`);
console.log(recipes.forth.ingredients[0]);
console.log(recipes.forth.ingredients[1]);

console.log(recipes.fifth.title);
console.log(`serves:${recipes.fifth.serves}`);
console.log(`ingredients:`);
console.log(recipes.fifth.ingredients[0]);
console.log(recipes.fifth.ingredients[1]);
console.log(recipes.fifth.ingredients[2]);
console.log(recipes.fifth.ingredients[3]);
7 changes: 6 additions & 1 deletion 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 countryObj = {};
for (let i = 0; i < countryCurrencyCodes.length; i++) {
countryObj[countryCurrencyCodes[i][0]] = countryCurrencyCodes[i][1];
}
return countryObj;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +39,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
34 changes: 30 additions & 4 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 @@ -20,6 +20,25 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
let shoppingFor = {};
let shoppingList = [];
// shoppingList= pantryItems.filter(item => !recipe["ingredients"].includes(item))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done solving the task! Why comment out these two lines in preference for the for loop?

// let pantryItems=pantry["fridgeContents"].concat(pantry["cupboardContents"])

for (let item of recipe.ingredients) {
if (
!(
pantry["fridgeContents"].includes(item) ||
pantry["cupboardContents"].includes(item)
)
) {
shoppingList.push(item);
}
}

shoppingFor.name = recipe.name;
shoppingFor.items = shoppingList;
return shoppingFor;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -43,11 +62,18 @@ test("createShoppingList works for pancakes recipe", () => {
test("createShoppingList works for margherita pizza recipe", () => {
let recipe2 = {
name: "margherita pizza",
ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"],
ingredients: [
"flour",
"salt",
"yeast",
"tinned tomatoes",
"oregano",
"mozarella",
],
};

expect(createShoppingList(recipe2)).toEqual({
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
items: ["flour", "yeast", "mozarella"],
});
});
});
16 changes: 15 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ const MENU = {

let cashRegister = {
// write code here
}
orderBurger(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.

This is great :) Can you think of a way to avoid duplicating the price of the burger and falafel? Can you think of a reason we'd want to avoid duplicating the price all over the code?

if (balance >= 6.5) {
return balance - 6.5;
} else {
return balance;
}
},
orderFalafel(balance) {
if (balance >= 7.25) {
return balance - 7.25;
} else {
return balance;
}
},
};

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