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

// write code here
// write code here
let mole = {
title: "Mole",
serves: "2",
ingredients: ["cinnamon", "cumin", "cocoa"],

}
console.log(mole.title);
console.log(`Serves: ${mole.serves}`);
console.log("Ingredients:")
mole.ingredients.forEach((ingredient) => {
console.log(ingredient);
});


let pannaCota = {
title: "Panna Cotta",
serves: "4",
cookingTime: " 5 min",
ingredients: ["milk", "gelatine", "strawberry", "lemon", "sugar", "double cream", "vanilla"],
}
console.log(pannaCotta.title);
console.log(`Serves: ${pannaCotta.serves}`);
console.log("Ingredients:")
pannaCotta.ingredients.forEach((ingredient) => {
console.log(ingredient);
});

let byrek = {
title: "Byrek",
serves: "4",
prepTime="30min",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

= should be :
and there are trailing commas

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you Jonathan for your feedback ,but i'm not sure if it should be : as they are objects

Copy link
Copy Markdown

@jxz12 jxz12 Apr 3, 2023

Choose a reason for hiding this comment

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

I do think objects need to be :, you can try to run the code yourself using node 2-mandatory/1-recipes.js to see!

cookingTime: "30 min",
doughIngredients={
["water", "flour", "salt"],
},
filling=["spinach", "spring onions", "feta", "salt", "olive oil"],

}

console.log(byrek.title);
console.log(`Serves: ${byrek.serves}`);
console.log("Ingredients:")
byrek.doughIngredients.forEach((ingredient) => {
console.log(ingredient);
});
20 changes: 18 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];

function createLookup(countryCurrencyCodes) {
// write code here
// function createLookup(countryCurrencyCodes) {
// currencyPairs = {}

// countryCurrencyCodes.forEach(([el,curr])=>{
// currencyPairs[el]=curr
// })
// return currencyPairs;

// }

function createLookup(countryCurrencyCodes){
let countryCurrencyCodesLookup={};

for (let countryCurrencyCode of countryCurrencyCodes){
countryCurrencyCodesLookup[countryCurrencyCode[0]]=countryCurrencyCode[1];
}
return countryCurrencyCodesLookup
}


/* ======= 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
19 changes: 16 additions & 3 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,8 +19,21 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
}
let shoppingList = {};
shoppingList.items = [];
shoppingList.name = recipe.name
// check ungredients
for (let ingredient of recipe.ingredients) {

if (!pantry.fridgeContents.includes(ingredient)
&& !pantry.cupboardContents.includes(ingredient)) {

shoppingList.items.push(ingredient);

}
}
return shoppingList;
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand Down
17 changes: 16 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ const MENU = {
};

let cashRegister = {
// write code here

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

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

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
32 changes: 25 additions & 7 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,59 @@ 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", () => {
test("a score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toBe("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)).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");
});
33 changes: 31 additions & 2 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 Down Expand Up @@ -56,14 +56,24 @@ function formatCourseworkResult(trainee) {
}
*/

test("formatCourseworkResult returns the correct string for trainee Xin", () => {
const trainee = { name: "Xin", score: 63 };
const result = formatCourseworkResult(trainee);
expect(result).toBe("Xin's coursework was marked as grade C.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Mona",
score: 78
}
*/

test("formatCourseworkResult returns the correct string for trainee Mona", () => {
const trainee = { name: "Mona", score: 78 };
const result = formatCourseworkResult(trainee);
expect(result).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 @@ -74,13 +84,27 @@ function formatCourseworkResult(trainee) {
}
*/

test("trainee with score 49 is grade E", () => {
const trainee = { name: "Ali", score: 49, age: 33, subjects: ["JavaScript", "React", "CSS"] };
const expectedOutput = "Ali's coursework was marked as grade E.";
const result = formatCourseworkResult(trainee);
expect(result).toEqual(expectedOutput);
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/
test("formatCourseworkResult returns the correct string for trainee with no name but a valid score", () => {
const trainee = { score: 90, age: 29 };
const result = formatCourseworkResult(trainee);
expect(result).toBe("Error: No trainee name!");
});



/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -89,3 +113,8 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("formatCourseworkResult returns the correct string for trainee Aman with no score", () => {
const trainee = { name: "Aman", subjects: ["HTML", "CSS", "Databases"] };
const result = formatCourseworkResult(trainee);
expect(result).toBe("Error: Coursework percent is not a number!");
});