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
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let dog = {
Log the name and breed of this dog using dot notation.
*/

let dogName; // complete the code
let dogBreed; // complete the code
let dogName = dog.name; // complete the code
let dogBreed = dog.breed; // complete the code
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

good use of dot notation

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 :)


console.log(`${dogName} is a ${dogBreed}`);

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let capitalCities = {
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code
let myCapitalCity = capitalCities[myCountry]; // complete the code

console.log(myCapitalCity);

Expand Down
3 changes: 2 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let basketballTeam = {
*/

// write code here

let sortedPlayers = basketballTeam.topPlayers.sort();
sortedPlayers.forEach(player => console.log(player));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

good use of foreach

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 :)


/* EXPECTED RESULT

Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ let capitalCities = {

// write code here

capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.Peru = {};
capitalCities.Peru.name = "Lima";
capitalCities.Peru.population = 9750000;

console.log(capitalCities);

/* EXPECTED RESULT
Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ let student = {

// write code here

student["attendance"] = 90;

/*
- Write an "if" statement that changes the value of hasPassed to true
if the student has attendance that is equal or greater than 90
Expand All @@ -27,6 +29,10 @@ let student = {

// write code here

if (student["attendance"] >= 90 && student["examScore"] > 60) {
student["hasPassed"] = true;
}

console.log(student);

/* EXPECTED RESULT
Expand Down
5 changes: 5 additions & 0 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ let car = {

console.log(car["colour"]);

//In this example "colour" property does not exist in the "car" object

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
Expand All @@ -27,6 +29,8 @@ let user = {

sayHelloToUser(user);

//"user" object does not have a "firstName" property

// Example 3
let myPet = {
animal: "Cat",
Expand All @@ -36,3 +40,4 @@ let myPet = {
};

console.log(myPet.getName());
//"getName" method does not have a return statement to return the name of the pet.
3 changes: 3 additions & 0 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

let student = {
// write code here
getName: function(name) {
console.log(`Student name: ${name}`)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice job with the exercises!

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.

Appreciated

student.getName("Daniel");
Expand Down
75 changes: 74 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,77 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here

// First Recipe
const recipe1 = {
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this looks good, no issues with your objects. But you could try to do this as a nested object instead?

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.

Will do!


console.log(recipe1.title);
console.log(`Serves: ${recipe1.servings}`);
console.log("Ingredients: ");
for (let i = 0; i < recipe1.ingredients.length; i++) {
console.log(recipe1.ingredients[i]);
}

// Second recipe
const recipe2 = {
title: "Pasta Bolognese",
servings: 3,
ingredients:["pasta", "onion", "garlic", "500g beef mince", "tomato sos", "olive oil"]
};

console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log("Ingredients: ");
for (let i = 0; i < recipe2.ingredients.length; i++) {
console.log(recipe2.ingredients[i]);
}

// Third Recipe

const recipe3 = {
title: "Pizza",
servings: 4,
ingredients: ["dough", "salami", "tomato sos", "ham", "cheese"]
};

console.log(recipe3.title);
console.log(`Serves ${recipe3.servings}`);
console.log("Ingredients: ");
for (let i = 0; i < recipe3.ingredients.length; i++) {
console.log(recipe3.ingredients[i]);
}

// Forth Recipe

const recipe4 = {
title: "Snitzels and chips",
servings: 3,
ingredients: ["chicken breast", "eggs", "flour", "oil", "potatos"]
};

console.log(recipe4.title);
console.log(`Serves ${recipe4.servings}`);
console.log("Ingredients: ");
for (let i = 0; i < recipe4.ingredients.length; i++) {
console.log(recipe4.ingredients[i]);
}

//Fifth Recipe

const recipe5 = {
title: "Meatballs pasta",
servings: 3,
ingredients: ["beef", "pasta", "tomato sos", "garlic", "oil"]
};

console.log(recipe5.title);
console.log(`Serves ${recipe5.servings}`);
console.log("Ingredients: ");
for (let i = 0; i < recipe5.ingredients.length; i++) {
console.log(recipe5.ingredients[i]);
}
8 changes: 8 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
for (let i = 0; i < countryCurrencyCodes.length; i++) {
const countryCurrency = countryCurrencyCodes[i];
const countryCode = countryCurrency[0];
const currencyCode = countryCurrency[1];
lookup[countryCode] = currencyCode;
}
return lookup;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
14 changes: 14 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ let pantry = {

function createShoppingList(recipe) {
// write code here

let missingItems = [];

for (let i = 0; i < recipe.ingredients.length; i++) {
let ingredient = recipe.ingredients[i];
if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good! Nice use of ! and &&
--have you thought about concatenating the fridge and cupboard ingredients first?

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.

Had problems with this one and checked GPT for help

missingItems.push(ingredient);
}
}

return {
name: recipe.name,
items: missingItems,
};
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
13 changes: 13 additions & 0 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@ const MENU = {

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

Choose a reason for hiding this comment

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

nice job! Very clean writing of this function

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.

ta :)

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

orderFalafel(balance) {
if (balance >= MENU.falafel) {
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
32 changes: 24 additions & 8 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,57 @@ 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
*/

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");
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

your tests look good! Nice job
--Could you think of other ways to write the tests?

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.

Yes! We can solve this using If/else statements, using an array to a function that converts score to grade, or using switch.

/*
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");
});
11 changes: 6 additions & 5 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ function formatCourseworkResult(trainee) {
- (Reminder: You must have run `npm install` one time before this will work!)
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{

// Write a test that checks the output of formatCourseworkResult when passed the following trainee:
test("trainee has a score of 63", () => {})
const trainee = {
name: "Xin",
score: 63
}
*/
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Think you are missing a bit with these tests....

Take a look at the expect function :)

Also-- I think there are about 4 more tests after this one which should be updated!

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.

I will look into this.



/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand Down