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
3 changes: 2 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let basketballTeam = {
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/

let array=basketballTeam.topPlayers;
console.log(array.sort());
// write code here
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great job, we wanted to see the name of each player so you should do this instead:

basketballTeam.topPlayers.sort().map(eachPlayer =>. console.log(eachPlayer))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Its concise and so neat ! I will try and refactor mine



Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ let capitalCities = {
*/

// write code here

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

/* EXPECTED RESULT
Expand Down
5 changes: 3 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let student = {
- Set the value of attendance to 90
*/

// write code here
student["attendance"]=90;

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand All @@ -24,8 +24,9 @@ let student = {
exam score is above 60.
- Use bracket notation to change the value of hasPassed
*/
if (student["examScore"]>60 && student["attendance"]>=90)
student["hasPassed"] = true ;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good job, you can also add else :

`else{
student["hasPassed"] = false;

}`

// write code here

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 @@ -14,11 +14,11 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]);// undefined because color property has not been defined in object specification

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`);//undefined because firstName property has not been defined in object specification
}

let user = {
Expand All @@ -35,4 +35,4 @@ let myPet = {
},
};

console.log(myPet.getName());
console.log(myPet.getName());//undefined because the function getName() does not return value and hence undefined will be returned
3 changes: 3 additions & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

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

student.getName("Daniel");
Expand Down
51 changes: 50 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,55 @@
cocoa

You should write and log at least 5 recipes


*/

// write code here
let recipe = {
title :"Mole",
servings : 2 ,
ingredients : [
"cinnamon" , "cumin" , "cocoa"
],
displayRecipe : function (){
console.log(this.title);
console.log("Serves : "+ this.servings);
console.log("Ingredients:");
for (item of this.ingredients){
console.log(item);
}
}
}
let recipe1 = {
title :"Biryani",
servings : 2 ,
ingredients : [
"rice" , "spices" , "meat"
],
displayRecipe : function (){
console.log(this.title);
console.log("Serves : "+ this.servings);
console.log("Ingredients:");
for (item of this.ingredients){
console.log(item);
}
}
}
let recipe2 = {
title :"Anda Paratha",
servings : 2 ,
ingredients : [
"eggs" , "spices" , "atta" , "oil"
],
displayRecipe : function (){
console.log(this.title);
console.log("Serves : "+ this.servings);
console.log("Ingredients:");
for (item of this.ingredients){
console.log(item);
}
}
}
recipe.displayRecipe();
recipe1.displayRecipe();
recipe2.displayRecipe();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great job and a great idea, but the question did not want you to have a method inside of each recipe, it is important to do what the questions ask us to do, you should find a way to go through each recipe and console.log the recipe items.
hint: you can have array of objects

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 @@ -18,8 +18,13 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let codesObject = {};
countryCurrencyCodes.forEach(element => {
codesObject[element[0]] = element[1];
});
return codesObject;
}
createLookup(COUNTRY_CURRENCY_CODES);

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand Down
13 changes: 11 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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

*/

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

function createShoppingList(recipe) {
// write code here
let shoppingList = {};
shoppingList.name = recipe.name;
shoppingList.items = [];
recipe.ingredients.map(item => {
if (!pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item))
shoppingList.items.push(item);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great job, you can use concat function from Javascript to combine both arrays and have one array and check the items in that array ==> let allIHave = pantry.fridgeContents.concat(cupBoardContents)

});
return shoppingList;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down Expand Up @@ -50,4 +58,5 @@ test("createShoppingList works for margherita pizza recipe", () => {
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
});
});
});

13 changes: 11 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- the method should return the new balance

Add another method to the cashRegister object which is called orderFalafel and handles ordering a falafel, in the same way as ordering a burger.

*/

const MENU = {
Expand All @@ -20,8 +21,16 @@ const MENU = {
};

let cashRegister = {
// write code here
}

orderBurger: function (balance) {
if (balance >= MENU.burger) balance = balance-MENU.burger;
return balance;
},
orderFalafel: function(balance){
if (balance >= MENU.falafel) balance = 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
10 changes: 10 additions & 0 deletions 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
- Loops or forEach
- Comparison inside if statements
- Setting values on an object
if (string === "") {
return wordCount;
}
string.split(" ").forEach((word) => {
if (wordCount[word] >= 1) {
wordCount[word]++;
} else {
wordCount[word] = 1;
}
});
*/

function countWords(string) {
Expand Down