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
80 changes: 62 additions & 18 deletions 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
/*
The Recipe Card
Never forget another recipe!

Create an object to hold information on your favorite recipe.
const recipe1 = {
title: "burger",
servings: 2,
ingredients: ["beef", "bun", "cheese", "ketchup"]
};

It should have properties for

- title (a string),
- servings (a number), and
- ingredients (an array of strings)
console.log(recipe1.title);
console.log(`Serves: ${recipe1.servings}`);
console.log("Ingredients:");
recipe1.ingredients.forEach(ingredient => console.log(ingredient));
console.log("\n");

On separate lines (one console.log statement for each), log the recipe information so it looks like:

Mole
Serves: 2
Ingredients:
cinnamon
cumin
cocoa
const recipe2 = {
title: "creamy Chicken pasta",
servings: 4,
ingredients: ["chicken breasts", "doubble cream", "chedar cheese", "mushroom", "onion", "pasta"]
};

You should write and log at least 5 recipes
*/

// write code here
console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log("Ingredients:");
recipe2.ingredients.forEach(ingredient => console.log(ingredient));
console.log("\n");


const recipe3 = {
title: "Spaghetti Bolognese",
servings: 6,
ingredients: ["spaghetti", "ground beef", "onion", "garlic", "tomato sauce", "tomato paste", "red wine", "olive oil"]
};


console.log(recipe3.title);
console.log(`Serves: ${recipe3.servings}`);
console.log("Ingredients:");
recipe3.ingredients.forEach(ingredient => console.log(ingredient));
console.log("\n");


const recipe4 = {
title: "Kuru Fasulye",
servings: 4,
ingredients: ["beans", "carrots", "beef diced", "cellerey", "onion", "spice", "peper paste"]
};


console.log(recipe4.title);
console.log(`Serves: ${recipe4.servings}`);
console.log("Ingredients:");
recipe4.ingredients.forEach(ingredient => console.log(ingredient));
console.log("\n");


const recipe5 = {
title: "brownies",
servings: 24,
ingredients: ["butter", "brown sugar", "white sugar", "eggs", "vanilla extract", "flour", "baking soda", "salt", "chocolate chips"]
};


console.log(recipe5.title);
console.log(`Serves: ${recipe5.servings}`);
console.log("Ingredients:");
recipe5.ingredients.forEach(ingredient => console.log(ingredient));
console.log("\n");
13 changes: 12 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,20 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
const keys = {};

for (let i = 0; i < countryCurrencyCodes.length; i++) {
const [countryCode, currencyCode] = countryCurrencyCodes[i];
keys[countryCode] = currencyCode;
}

return keys;
}

const countryCurrencyLookup = createLookup(COUNTRY_CURRENCY_CODES);
console.log(countryCurrencyLookup);


/* ======= 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
22 changes: 21 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,29 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here

const missingIngredients = [];
for (let i = 0; i < recipe.ingredients.length; i++) {
const ingredient = recipe.ingredients[i];
if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) {
missingIngredients.push(ingredient);
}
}
return {
name: recipe.name,
items: missingIngredients
};
}

const recipe = {
name: "Carrot Cake",
ingredients: ["all-purpose flour", "baking powder", "baking soda", "ground cinnamon", "brown sugar", "vegetable oil", "eggs", "vanilla extract", "grated carrots", "chopped walnuts", "cream cheese", "unsalted butter"]
};

const shoppingList = createShoppingList(recipe);
console.log(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
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: function(balance) {
if (balance - MENU.burger >= 0) {
balance -= MENU.burger;
}
return balance;
},
orderFalafel: function(balance) {
if (balance - MENU.falafel >= 0) {
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
29 changes: 25 additions & 4 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,62 @@ 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
*/
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");
});
34 changes: 31 additions & 3 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,25 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/

it("returns the expected string for a trainee with a score of 63", () => {
const trainee = { name: "Xin", score: 63 };
const expected = "Xin's coursework was marked as grade C.";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expected);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Mona",
score: 78
}
*/

it("returns the expected string for a trainee with a score of 78", () => {
const trainee = { name: "Mona", score: 78 };
const expected = "Mona's coursework was marked as grade B.";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expected);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
Expand All @@ -74,18 +84,36 @@ function formatCourseworkResult(trainee) {
}
*/

it("returns an error message if the trainee's score is not a number", () => {
const trainee = { name: "Ali", score: "49%", age: 33, subjects: ["JavaScript", "React", "CSS"] };
const expected = "Error: Coursework percent is not a number!";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expected);
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/

it("returns an error message if the trainee's name is missing", () => {
const trainee = { score: 90, age: 29 };
const expected = "Error: No trainee name!";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expected);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
it("returns an error message if the trainee's score is missing", () => {
const trainee = { name: "Aman", subjects: ["HTML", "CSS", "Databases"] };
const expected = "Error: Coursework percent is not a number!";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expected);
});