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
38 changes: 37 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,40 @@
You should write and log at least 5 recipes
*/

// write code here
let coffee = {
title: "cup of coffee",
serving: 1,
ingredients: ["coffee", "sugar", "hot water", "milk"],
};

let tea = {
title: "cup of tea",
serving: 1,
ingredients: ["tea bag", "hot water", "honey"],
};

let glassOfWater = {
title: "water",
serving: 1,
ingredients: ["water", "cup"],
};

let boiledEgg = {
title: "egg",
serving: 1,
ingredients: ["egg", "boiling water"],
};

let bread = {
title: "bread",
serving: 1,
ingredients: ["flour", "water"],
};



console.log([coffee])
console.log([tea])
console.log([glassOfWater])
console.log([boiledEgg])
console.log([bread])
9 changes: 8 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let 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
14 changes: 12 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,17 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let shoppingList = {
name:recipe.name,
items:[],
};

for (let item of recipe.ingredients){
if (!pantry.cupboardContents.includes(item) && !pantry.fridgeContents.includes(item)){
shoppingList.items.push(item);
}
}
return shoppingList;
}

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

let cashRegister = {
// write code here
}

orderBurger: function(balance) {
if (balance - MENU.burger >= 0) {
balance = balance - MENU.burger;
};
return balance;

},

orderFalafel: function(balance) {
if (balance - MENU.falafel >= 0) {
balance = 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
25 changes: 18 additions & 7 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,29 @@ 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", () => {
/* Remove the .skip above, then write the test body. */
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 68 is grade C
*/
Expand All @@ -65,11 +69,18 @@ test.skip("a score of 71 is grade B", () => {
/*
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");
});
36 changes: 35 additions & 1 deletion 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 Down Expand Up @@ -55,6 +55,13 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
let trainee1 = {
name: "Xin",
score: 63,
}
test("if Xin's grade is C", () => {
expect(formatCourseworkResult(trainee1)).toBe("Xin's coursework was marked as grade C.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -63,6 +70,13 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/
let trainee2 = {
name: "Mona",
score: 78,
}
test("if Mona's grade is B", () => {
expect(formatCourseworkResult(trainee2)).toBe("Mona's coursework was marked as grade B.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -73,6 +87,13 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
let trainee3 = {
name: "Ali",
score: 49,
}
test("if Ali's grade is E", () => {
expect(formatCourseworkResult(trainee3)).toBe("Ali's coursework was marked as grade E.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -81,6 +102,13 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
let trainee4 = {

score: 90,
}
test("if trainee's name isn't provided", () => {
expect(formatCourseworkResult(trainee4)).toBe("Error: No trainee name!");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -89,3 +117,9 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
let trainee5 = {
name: "Aman",
}
test("if trainee's score isn't provided", () => {
expect(formatCourseworkResult(trainee5)).toBe("Error: Coursework percent is not a number!");
});