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
35 changes: 27 additions & 8 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,43 @@
*/

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(`${dogName} is a ${dogBreed}`);
// complete the code

/* let dogName= "Spot";
let dogBreed= "Dalmatian"; */

console.log(`${dog.name} is a ${dog.breed}`);


/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/


/* const house = {
livingRoom: true,
kitchen: ["fork", "spoon"],
swimmingPool: {
water: true,
degree: 30
},
myHouse: function(){
console.log(`${this.swimmingPool.degree}`)
}
}

house.myHouse() */
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"; // complete the code

console.log(myCapitalCity);

Expand Down
6 changes: 6 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,12 @@ let capitalCities = {
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000
capitalCities.China.population = 21500000
capitalCities.Peru = {
name: 'Lima',
population: 9750000
}

console.log(capitalCities);

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
student["attendance"] >= 90 && student["examScore"] > 60
? (student["hasPassed"] = true)
: (student["hasPassed"] = false);

console.log(student);

Expand Down
4 changes: 2 additions & 2 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"]);// because the property color not exit

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`);// is undefine because property firsName ot exist, exit name, the correct is `${user.name}`
}

let user = {
Expand Down
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 (string) {
console.log(`Student name: ${string}`)
}
}


student.getName("Daniel");

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

// write code here
let recipeCard = [
{
title: "Avocado Smoothie",
servings: 1,
ingredients: ['avocado', 'oat milk', 'peanut butter', 'honey'],
},
{
title: "Oat Smoothie",
servings: 1,
ingredients: ['oats', 'milk', 'greek yogurt', 'honey'],
},
{
title: "pancakes",
servings: 1,
ingredients: ['egg', 'butter', 'oat flour', 'oat milk', 'banana'] ,
},
{
title: "carrot soup" ,
servings: 1,
ingredients: ['chicken soup', 'carrot', 'onion', 'olive oil'],
},
{
title: "Bravas potatoes",
servings: 1,
ingredients: ['potatoes', 'paprika', 'garlic', 'parsley'],
}];

recipeCard.forEach((recipe) => {
console.log(recipe.title);
console.log(`Serves: ${recipe.servings}`);
console.log("Ingredients:")
recipe.ingredients.forEach((ingredient) => console.log(ingredient));
console.log("\n");
});
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 @@ -19,8 +19,18 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
//const countryCurrencyCodes = Object.fromEntries(countryCurrencyCodes);
// countryCurrencyCodes.forEach(())
let result = {};
for (let i = 0; i < countryCurrencyCodes.length; i++){
result[countryCurrencyCodes[i][0]] = countryCurrencyCodes[i][1]
}
//return Object.fromEntries(countryCurrencyCodes);
return result
}

//console.log(createLookup(COUNTRY_CURRENCY_CODES))

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand All @@ -34,4 +44,6 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});


13 changes: 11 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,16 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let missingIngredients = [];
for (let i = 0; i < recipe.ingredients.length; i++) {
if (!pantry.fridgeContents.includes(recipe.ingredients[i]) && !pantry.cupboardContents.includes(recipe.ingredients[i])) {
missingIngredients.push(recipe.ingredients[i]);
}
}
return {
name: recipe.name,
items: missingIngredients
};
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
8 changes: 8 additions & 0 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const MENU = {

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

orderFalafel: function (balance) {
return balance >= MENU.falafel ? balance - MENU.falafel : balance;
}

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
39 changes: 25 additions & 14 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ function convertScoreToGrade(score) {
grade = "C";
} else if (score >= 50) {
grade = "D";
} else {
} else {
grade = "E";
}

return grade;
}


/* ======= TESTS - FOR THIS EXERCISE YOU SHOULD MODIFY THEM! =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 5-writing-tests.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand All @@ -34,42 +35,52 @@ function convertScoreToGrade(score) {
The first test has been written for you. You need to fix the test so that it
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
});

/*
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", () => {
/* Remove the .skip above, then write the test body. */
});
/*
Write a test that checks a score of 68 is grade C
Write a test that checks a score of 83 is grade A
*/

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

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

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

/*
Write a test that checks a score of 49 is grade E
*/

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

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