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

// write code here
const recipe = {
title: 'pasta dough',
servings: 2,
ingredients: ['2 cups flour', '3 large eggs, at room temperature', '2 tablespoons olive oil', '1 teaspoon salt', '2 tablespoons water, or as needed']
};

console.log(recipe.title);
console.log(`Serves: ${recipe.servings}`);
console.log('Ingredients:');
recipe.ingredients.forEach(ingredient => console.log(ingredient));


// Pasta dough
// Serves: 2
// Ingredients:
// 2 cups flour
// 3 large eggs, at room temperature
// 2 tablespoons olive oil
// 1 teaspoon salt
// 2 tablespoons water, or as needed
11 changes: 10 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];


function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
countryCurrencyCodes.forEach(([country, currency]) => {
lookup[country] = currency;
});
return lookup;
}

const lookup = createLookup(COUNTRY_CURRENCY_CODES);
console.log(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
15 changes: 14 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ let pantry = {
cupboardContents: ["salt", "tinned tomatoes", "oregano"],
};



function createShoppingList(recipe) {
// write code here

let shoppingList = {
items: [],
}
recipe.ingredients.forEach((ingredient) => {
if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)){
shoppingList.items.push(ingredient)
}
});
shoppingList.name = recipe.name
return shoppingList
}


/* ======= 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
27 changes: 25 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,31 @@ const MENU = {
};

let cashRegister = {
// write code here
}
orderBurger(balance) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and works but this is the shorthand approach of adding a method into an object, just to check understanding, do you know how you would define this method without using the shorthand approach? Ie by defining fully the key and the value separately?

if (balance >= MENU.burger) {
balance -= MENU.burger;
}
return balance;
},

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

let balance = 10;

// order a burger
balance = cashRegister.orderBurger(balance);

// order a falafel
balance = cashRegister.orderFalafel(balance);

console.log(balance);


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
28 changes: 24 additions & 4 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,62 @@ 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");
// test("a score of 83 is grade A", () => {
// expect(convertScoreToGrade(83), "Z");
// });

test("a score of 83 is grade A", () => {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", () => {
/* Remove the .skip above, then write the test body. */
// 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)).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 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");
});
43 changes: 43 additions & 0 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
function convertScoreToGrade(score) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you might have a bit of stray code copied from above? You can delete this and up till the beginning of line 61 to fix

let grade = null;

if (score >= 80) {test("checks the output of formatCourseworkResult", () => {
let trainee = {
name: "Xin",
score: 63,
};
expect(formatCourseworkResult(trainee)).toEqual("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 +73,13 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/
test("checks the output of formatCourseworkResult", () => {
let trainee = {
name: "Mona",
score: 78,
};
expect(formatCourseworkResult(trainee)).toEqual("Mona's coursework was marked as grade B.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -74,13 +91,31 @@ function formatCourseworkResult(trainee) {
}
*/

test("checks the output of formatCourseworkResult", () => {
let trainee = {
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"],
};
expect(formatCourseworkResult(trainee)).toEqual("Ali's coursework was marked as grade E.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/
test("checks the output of formatCourseworkResult", () => {
let trainee = {
score: 90,
age: 29,
};
expect(formatCourseworkResult(trainee)).toEqual("Error: No trainee name!");
});


/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -89,3 +124,11 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/

test("checks the output of formatCourseworkResult", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"],
};
expect(formatCourseworkResult(trainee)).toEqual("Error: Coursework percent is not a number!");
});