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= "Spot"; // complete the code
let dogBreed= "Dalmatian"; // 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= "London"; // complete the code

console.log(myCapitalCity);

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

// write code here
//let sortedTeam = (basketballTeam.topPlayers.sort());
let sorted = basketballTeam.topPlayers.sort();
//console.log(sorted[0]);
//console.log(sorted[1]);
//console.log(sorted[2]);

for (let i = 0; i < sorted.length; i++) {
console.log(sorted[i]);

}

/* EXPECTED RESULT

Expand Down
9 changes: 5 additions & 4 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
population: 21500000,
},
Peru: { name: "Lima", population: 9750000 },
};

/*
Expand All @@ -23,8 +25,7 @@ let capitalCities = {
*/

// write code here

console.log(capitalCities);
(capitalCities.UnitedKingdom.population = 8980000), console.log(capitalCities);

/* EXPECTED RESULT

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

*/
*/
4 changes: 4 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,8 @@ let student = {
*/

// write code here
student['attendance'] = 90; // Bracket notation
// student.attendance = 90; Dot notation

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand All @@ -26,7 +28,9 @@ let student = {
*/

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

}
console.log(student);

/* EXPECTED RESULT
Expand Down
3 changes: 3 additions & 0 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ let car = {
};

console.log(car["colour"]);
//we don't have any colour key.

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
//we don't have the firstName key - that's why it is undefined.
}

let user = {
Expand All @@ -34,5 +36,6 @@ let myPet = {
"My pet's name is Fluffy";
},
};
//It is undefined because the method hasn't taken any argument

console.log(myPet.getName());
5 changes: 4 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/

let student = {
getName: (name) => {
console.log(`Student name: ${name}`);

}
// write code here
}

Expand All @@ -16,5 +20,4 @@ student.getName("Daniel");
/* EXPECTED RESULT

Student name: Daniel

*/
17 changes: 17 additions & 0 deletions 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,22 @@

You should write and log at least 5 recipes
*/
//three is enough XD
let recipeCereal = {
title:"Cereal",
serves: 2,
ingredients : [ "milk","cereal"],
}
let recipeSpanishOmelette = {
tittle: "SpanishOmelette",
serves: 2,
ingredients : ["onion", "potato","egg","olive oil", "salt"],
}
let recipeSmoothie ={
tittle: "Smoothie",
serves: 2,
ingredients: ["banana","Strawberry","oat milk","ice"],
}


// write code here
9 changes: 9 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
const obj = {}
for (let i = 0; i < countryCurrencyCodes.length; i++) {
const element = countryCurrencyCodes[i];
const country = element[0];
const currency = element[1];
obj[country]= currency;
}
return obj;
//console.log(obj);
// write code here
}

Expand Down
22 changes: 19 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
//const allIngredients = pantry.fridgeContents.concat(pantry.cupboardContents);
const missingIng = recipe.ingredients.filter(
(item) => !pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item)
);
return {
name: recipe.name,
items: missingIng,
};
}


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand All @@ -43,11 +52,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"],
});
});
});
24 changes: 20 additions & 4 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
Add a method to the cashRegister object
- the method name should be orderBurger
- the method should take one argument called balance, which is a number
- the method should check if there is enough money in the balance to order a burger (i.e. will the balance be greater than or equal to 0 if the burger is ordered)
- if there is enough money in the balance to order the burger, then the price of the burger should be subtracted from the balance
- the method should check if there is enough money in the balance to order a burger (i.e. will the balance be greater
than or equal to 0 if the burger is ordered)
- if there is enough money in the balance to order the burger, then the price of the burger should be subtracted from
the balance
- 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.
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 +23,21 @@ const MENU = {
};

let cashRegister = {
orderBurger: (balance) => {
if (balance >= MENU.burger) {
return balance - MENU.burger;
} else return balance;
},

orderFalafel: (balance) => {
if (balance >= MENU.falafel) {
return balance - MENU.falafel;
} else if (balance < MENU.falafel) {
return balance;
}
},
// write code here
}
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
30 changes: 24 additions & 6 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,59 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83)).toEqual("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", () => {
expect(convertScoreToGrade(71)).toEqual("B");
/* Remove the .skip above, then write the test body. */
});
/*
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 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