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
13 changes: 12 additions & 1 deletion 2-mandatory/1-recipes.js

Choose a reason for hiding this comment

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

👍

Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here
let Recipe = {

Choose a reason for hiding this comment

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

it is a common javascript coding standard to have variable names that are camel cased : https://www.w3schools.com/js/js_conventions.asp

PascalCasing (such as your usage in "Recipe") is normally used for class definitions

title: "Mole" , //(a string),
servings: 2 , //a number), and
ingredients: ["cinnamon", "cumin", "cocoa"] //(an array of strings)

};
console.log(Recipe.title);
console.log(`Serves: ${Recipe.servings}`);
console.log(Recipe.ingredients[0]);
console.log(Recipe.ingredients[1]);
console.log(Recipe.ingredients[2]);
Comment on lines +34 to +36

Choose a reason for hiding this comment

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

❓ how could you change this to handle a variable amount of ingredients without adding any additional lines of code

💡 hint: https://www.w3schools.com/jsref/jsref_foreach.asp

7 changes: 7 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js

Choose a reason for hiding this comment

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

Nice and concise 👍

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here

let res = {};
for( let [countrycodes, currencycodes] of countryCurrencyCodes){

Choose a reason for hiding this comment

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

👍 nice use of destructuring here


res[countrycodes] = currencycodes;
};
return res;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
12 changes: 12 additions & 0 deletions 2-mandatory/3-shopping-list.js

Choose a reason for hiding this comment

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

👍

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ let pantry = {
};

function createShoppingList(recipe) {

// write code here
let shoppingList={
name: recipe.name,
items:[]
}
for (let items of recipe.ingredients) {
if (!pantry.fridgeContents.includes(items) && !pantry.cupboardContents.includes(items)) {
shoppingList.items.push(items);
}

}
return shoppingList;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
22 changes: 21 additions & 1 deletion 2-mandatory/4-restaurant.js

Choose a reason for hiding this comment

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

❓ have you ran prettier on this code

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,28 @@ const MENU = {
};

let cashRegister = {
orderBurger:function(balance){
let finalBalance=balance;
let isBalanceBigEnough = balance - MENU.burger >= 0;
if (isBalanceBigEnough) {
finalBalance = balance - MENU.burger;
}
return finalBalance;
},

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


}
// write code here
}


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
34 changes: 29 additions & 5 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,65 @@ function convertScoreToGrade(score) {
passes.
*/
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


/* 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 68 is grade D", () => {
expect(convertScoreToGrade(55)).toEqual("D");
});

/*
Write a test that checks a score of 49 is grade E
*/
test("a score of 68 is grade E", () => {
expect(convertScoreToGrade(49)).toEqual("E");
});

/*
Write a test that checks a score of 30 is grade E
*/

test("a score of 68 is grade E", () => {
expect(convertScoreToGrade(30)).toEqual("E");
});
/*
Write a test that checks a score of 70 is grade B
*/
test("a score of 68 is grade B", () => {
expect(convertScoreToGrade(70)).toEqual("B");
});
Comment on lines 75 to +99

Choose a reason for hiding this comment

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

❓ Have you checked the names of these tests - it looks like you may have copy and pasted without updating

43 changes: 42 additions & 1 deletion 2-mandatory/6-writing-tests-advanced.js

Choose a reason for hiding this comment

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

Nothing wrong with your code here - the provided function "convertScoreToGrade" is missing the score parameter here which you will need to add to pass the tests

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("Xin's score returns the correct sentence", () => {
expect(
formatCourseworkResult({
name: "Xin",
score: 63,
})
).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,7 +71,14 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/

test("Mona's score returns the correct sentence", () => {
expect(
formatCourseworkResult({
name: "Mona",
score: 78,
})
).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 @@ -73,6 +88,16 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("Ali's score returns the correct sentence", () => {
expect(
formatCourseworkResult({
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
})
).toEqual("Ali's coursework was marked as grade D.");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -81,6 +106,14 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
test("test object with no name", () => {
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 +122,11 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("test object with no score", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
};

expect(formatCourseworkResult(trainee)).toEqual("Error: No trainee score!");
});