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/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ let capitalCities = {
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code
let myCapitalCity = capitalCities.UnitedKingdom;

console.log(myCapitalCity);
console.log(capitalCities[myCapitalCity]);

/* EXPECTED RESULT

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

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

student.getName("Daniel");

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

// write code here
// write code here
const dalRecipe = {
title: "Tadka Dal",
Serves: 2,
ingredients: ["veg-oil", "cumin", "cinnamon", "salt"],


}


console.log(dalRecipe.title);
console.log("Serves" + dalRecipe.Serves);
console.log("ingredients");
for(let i = 0; i < dalRecipe.ingredients.length; i++) {
console.log(dalRecipe.ingredients[i]);
}

13 changes: 10 additions & 3 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ const COUNTRY_CURRENCY_CODES = [
["NG", "NGN"],
["MX", "MXN"],
];

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

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +37,8 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});

function speak(line) {
console.log(`The ${this.type} rabbit says '${line}'`);
}
15 changes: 12 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@

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 = {
fridgeContents: ["butter", "milk"],
cupboardContents: ["salt", "tinned tomatoes", "oregano"],
};

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

// Output: { name: "Chocolate Cake", items: ["cocoa powder", "baking powder"] }


/* ======= 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 Down Expand Up @@ -50,4 +58,5 @@ test("createShoppingList works for margherita pizza recipe", () => {
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
});

});
14 changes: 13 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ const MENU = {
};

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

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

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
33 changes: 19 additions & 14 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,47 @@ 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).toEqual("A"));
// });
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
*/

/*
Write a test that checks a score of 68 is grade 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 E", () => {
expect(convertScoreToGrade(49)).toEqual("E");
})
/*
Write a test that checks a score of 30 is grade E
Write a test that checks a score of 30 is grade F
*/

// test("a score of 30 is F", () => {
// expect(convertScoreToGrade(30)).toEqual("F");
// })
/*
Write a test that checks a score of 70 is grade B
*/
48 changes: 39 additions & 9 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
trainee has completed.
*/

function convertScoreToGrade() {
function convertScoreToGrade(score) {
let grade = null;

if (score >= 80) {
Expand All @@ -28,20 +28,30 @@ function convertScoreToGrade() {
return grade;
}

// function formatCourseworkResult(trainee) {
// if (!trainee.name) {
// return "Error: No trainee name!";
// }
// let traineeName = trainee.name;

// if (typeof trainee.score != "number") {
// return "Error: Coursework percent is not a number!";
// }
// let traineeGrade = convertScoreToGrade(trainee.score);

// return `${traineeName}'s coursework was marked as grade ${traineeGrade}.`;
// }

function formatCourseworkResult(trainee) {
if (!trainee.name) {
return "Error: No trainee name!";
}
let traineeName = trainee.name;

if (typeof trainee.score != "number") {
if (typeof trainee.score !== "number") {
return "Error: Coursework percent is not a number!";
}
let traineeGrade = convertScoreToGrade(trainee.score);

return `${traineeName}'s coursework was marked as grade ${traineeGrade}.`;
return traineeGrade;
}

/* ======= TESTS - FOR THIS EXERCISE YOU SHOULD MODIFY THEM! =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 6-writing-tests-advanced.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand All @@ -55,6 +65,11 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("score more than 60 and less than 70 is C", function() {
expect(formatCourseworkResult({name: "Xin", score: 63})).toBe("C");
});



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

test("score more than 70 and less than 80 is B", function() {
expect(formatCourseworkResult({name: "Mona", score: 78})).toBe("B");
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
Expand All @@ -73,6 +90,9 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("trainee with coursework percent less than 50 returns grade E", function() {
expect(formatCourseworkResult({name: "Ali", score: 49, age: 33, subjects: ["JavaScript", "React", "CSS"]})).toBe("E")
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -81,11 +101,21 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/

test("trainee more than 80 and age 29 is grade A", function() {
expect(formatCourseworkResult({score: 90, age: 29})).toBe("Error: No trainee name!")
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("trainee with missing name returns error message", function() {
expect(formatCourseworkResult({name: "Aman", subjects: ["HTML", "CSS", "Databases"]})).toBe("Error: Coursework percent is not a number!")
});