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
13 changes: 7 additions & 6 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
*/

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
let dogName = "Spot"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should use the dot notation here the answer should be let dog.Name = "Spot"


let dogBreed ="Dalmatian"

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here as well the same :::dot notation

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 = "London";

console.log(myCapitalCity);

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

// write code here

let topPlayers = basketballTeam.topPlayers;
topPlayers.sort();
for (let player of topPlayers) {
console.log(player);
}


/* EXPECTED RESULT
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here you could make it easy by finding the index like this console.log(basketballTeam.topPlayers[index number ]);


Expand Down
7 changes: 7 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ 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 Down
7 changes: 7 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,12 @@ let student = {
*/

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




console.log(student);

Expand Down
5 changes: 5 additions & 0 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let car = {
};

console.log(car["colour"]);
//Answer : We are trying to access the value of property called Colour in the car but colour is not defined in car object.

// Example 2
function sayHelloToUser(user) {
Expand All @@ -27,6 +28,8 @@ let user = {

sayHelloToUser(user);

//Answer : we are passing an object called user as an argument to the sayHelloToUser function. The function tries to access the firstName property of the user object, but this property does not exist. Therefore, when we try to log the string "Hello undefined" to the console, we see undefined instead of the expected value.

// Example 3
let myPet = {
animal: "Cat",
Expand All @@ -36,3 +39,5 @@ let myPet = {
};

console.log(myPet.getName());

//Answer: This does not return any value,the getname method in the mypet object returns a string that describes the pet's name,while the method does not use the return keyword.
7 changes: 6 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

let student = {
// write code here
}

getName: function(name) {
console.log("Student name: " + name);
}


};
student.getName("Daniel");

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

// write code here
// write code here

let recipe1 = {
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
};

let recipe2 = {
title: "Pesto Pasta",
servings: 4,
ingredients: ["pasta", "basil", "garlic", "pine nuts", "olive oil"]
};

let recipe3 = {
title: "Guacamole",
servings: 6,
ingredients: ["avocado", "tomato", "onion", "lime", "cilantro"]
};

let recipe4 = {
title: "Chicken Curry",
servings: 3,
ingredients: ["chicken", "curry powder", "coconut milk", "onion", "garlic"]
};

let recipe5 = {
title: "Hummus",
servings: 8,
ingredients: ["chickpeas", "tahini", "lemon juice", "garlic", "olive oil"]
};

console.log(recipe1.title);
console.log(`Serves: ${recipe1.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe1.ingredients.length; i++) {
console.log(recipe1.ingredients[i]);
}
console.log("");

console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe2.ingredients.length; i++) {
console.log(recipe2.ingredients[i]);
}
console.log("");

console.log(recipe3.title);
console.log(`Serves: ${recipe3.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe3.ingredients.length; i++) {
console.log(recipe3.ingredients[i]);
}
console.log("");

console.log(recipe4.title);
console.log(`Serves: ${recipe4.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe4.ingredients.length; i++) {
console.log(recipe4.ingredients[i]);
}
console.log("");

console.log(recipe5.title);
console.log(`Serves: ${recipe5.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe5.ingredients.length; i++) {
console.log(recipe5.ingredients[i]);
}
console.log("");
6 changes: 6 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,12 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
for (let i = 0; i < countryCurrencyCodes.length; i++) {
const [countryCode, currencyCode] = countryCurrencyCodes[i];
lookup[countryCode] = currencyCode;
}
return lookup;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's great ,but if use object here is going be much easier


/* ======= TESTS - DO NOT MODIFY =====
Expand Down
7 changes: 7 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
let missingIngredients = recipe.ingredients.filter(
ingredient => !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)
);
return { name: recipe.name, items: missingIngredients };



}

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

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

orderFalafel: (balance) => {
if (balance >= MENU.falafel) {
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
34 changes: 25 additions & 9 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,57 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83)).toBe ("A");
});

/*
The rest of the tests have comments describing what to test and you need to
write a matching test
*/

test.skip("a score of 71 is grade B", () => {
test("a score of 71 is grade B", () => {
/* Remove the .skip above, then write the test body. */
expect(convertScoreToGrade(71)).toBe ("B");
});
/*
Write a test that checks a score of 68 is grade C
*/
*/test("a score of 68 is grade C", () => {
expect(convertScoreToGrade(68)).toBe ("C");
});

/*
Write a test that checks a score of 55 is grade D
*/

*/ test("a score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toBe ("D");
});

/*
Write a test that checks a score of 68 is grade C
*/
*/ test("a score of 68 is grade C", () => {
expect(convertScoreToGrade(68)).toBe ("C");
});

/*
Write a test that checks a score of 55 is grade D
*/
*/ test("a score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toBe ("D");
});

/*
Write a test that checks a score of 49 is grade E
*/
*/ test("a score of 49 is grade E", () => {
expect(convertScoreToGrade(49)).toBe ("E");
});

/*
Write a test that checks a score of 30 is grade E
*/
*/ test("a score of 30 is grade E", () => {
expect(convertScoreToGrade(30)).toBe ("E");
});

/*
Write a test that checks a score of 70 is grade B
*/
*/ test("a score of 70 is grade B", () => {
expect(convertScoreToGrade(70)).toBe ("B");
});
Loading