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; //dot notation using objectName.propertyName
let dogBreed = dog.breed; //dot notation using objectName.propertyName

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"]; // using bracket notation => objectName["propertyName"]

console.log(myCapitalCity);

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

// write code here
basketballTeam = basketballTeam["topPlayers"]; // using bracket notation => objectName["propertyName"]
console.log(basketballTeam);

basketballTeam.sort();
console.log(basketballTeam);

let sortedbasketballTeam= [...basketballTeam].sort();
console.log(sortedbasketballTeam);


/* EXPECTED RESULT
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 @@ -24,6 +24,12 @@ let capitalCities = {

// write code here

capitalCities.UnitedKingdom.population = 8980000; // objectName.objectName.propertyName = "newValue";
capitalCities.China.population = 21500000;
capitalCities.Peru = {};
capitalCities.Peru.name = "Lima";
capitalCities.Peru.population = 9750000;

console.log(capitalCities);

/* EXPECTED RESULT
Expand Down
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,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,9 @@ let student = {
*/

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

console.log(student);

Expand Down
9 changes: 6 additions & 3 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
*/

let student = {
// write code here
}

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



/* EXPECTED RESULT

Student name: Daniel
Expand Down
21 changes: 19 additions & 2 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
*/

// write code here
const recipes = [
{
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
},
{
title: "Pancakes",
servings: 4,
ingredients: ["flour", "sugar", "baking powder", "salt", "milk", "eggs", "butter"]
}];
recipes.forEach(recipe => {
console.log(recipe.title);
console.log(`Serves: ${recipe.servings}`);
console.log("Ingredients:");
recipe.ingredients.forEach(ingredient => {
console.log(ingredient);
});
});
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,8 +19,14 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
for (const [countryCode, currencyCode] of countryCurrencyCodes) {
lookup[countryCode] = currencyCode;
}
return lookup;
}


/* ======= 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 Down
10 changes: 10 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ let pantry = {

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

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

let cashRegister = {
// write code here
}
orderBurger(balance) {
if (balance >= MENU.burger) {
return balance - MENU.burger;
} else {
return balance;
}
},
orderFalafel(balance) {
if (balance >= MENU.falafel) {
return balance - MENU.falafel;
} else {
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)).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.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

*/

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

test("a score of 71 is grade B", () => {
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 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");
});
19 changes: 13 additions & 6 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ function formatCourseworkResult(trainee) {

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Xin",
score: 63
}
*/
*/
test("formatCourseworkResult returns correct output for trainee with score 63", () => {
const trainee = {
name: "Xin",
score: 63,
};
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -63,7 +65,12 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/

test("formatCourseworkResult returns correct output for trainee with score 63", () => {
const trainee = {
name: "Mona",
score: 78,
};
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
Expand Down