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
12 changes: 6 additions & 6 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
breed: "Dalmatian", //string
name: "Spot", //string
isHungry: true, //boolean
happiness: 6, //number
};

/*
You can access the values of each property using dot notation.
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

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

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

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code

let myCapitalCity = capitalCities[myCountry];
console.log(myCapitalCity);

/* EXPECTED RESULT
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 topPlayers = basketballTeam.topPlayers.sort();
topPlayers.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.

Nitpick: This would be slightly cleaner by omitting the parenthesis around player

topPlayers.forEach(player => console.log(player));

This is possible as the arrow function takes a single paramter


/* EXPECTED RESULT

Expand Down
7 changes: 6 additions & 1 deletion 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities["Peru"] = {};
capitalCities.Peru.name = "Lima";
capitalCities.Peru.population = 9750000;


console.log(capitalCities);

Expand Down
7 changes: 4 additions & 3 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ let student = {
- Add a property to the student object for attendance
- Set the value of attendance to 90
*/

// write code here
student["attendance"] = 90;

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand All @@ -25,7 +24,9 @@ let student = {
- Use bracket notation to change the value of hasPassed
*/

// write code here
if (student.attendance >= 90 && student.examScore > 60) {
student["hasPassed"] = true;
}

console.log(student);

Expand Down
7 changes: 5 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ let car = {
};

console.log(car["colour"]);
//there is no property called "colour" in car object

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}

let user = {
name: "Mira"
name: "Mira",
};

sayHelloToUser(user);
//you are calling a function that does not 'return' a value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The fact that the function doesn't return a value here doesn't matter. It will still run and the function includes a console.log so it will output to the console. Take another look and see if you can spot why the log will include an undefined value.


// Example 3
let myPet = {
animal: "Cat",
getName: function() {
getName: function () {
"My pet's name is Fluffy";
},
};

console.log(myPet.getName());
// the getName function does not 'return' a value
6 changes: 4 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
*/

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

student.getName("Daniel");

Expand Down
22 changes: 21 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,24 @@
You should write and log at least 5 recipes
*/

// write code here
let favouriteRecipes = [
{ name: "Mole", serves: 2, ingredients: ["cinnamon", "cumin", "cocoa"] },
{ name: "Cake", serves: 5, ingredients: ["flour", "eggs", "sugar"] },
{ name: "French Toast", serves: 1, ingredients: ["bread", "eggs", "milk"] },
{ name: "Pakora", serves: 3, ingredients: ["flour", "ginger", "potato"] },
{
name: "Baked Potato",
serves: 2,
ingredients: ["tuna", "cheese", "potato"],
},
];

console.log(favouriteRecipes);
favouriteRecipes.forEach((element) => {
console.log(element.name);
console.log(`Serves: ${element.serves}`);
console.log("Ingredients:");
element.ingredients.forEach((ingredient) => {
console.log(ingredient);
});
});
6 changes: 5 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const COUNTRY_CURRENCY_CODES = [
];

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: You must use let or const to declare a new variable

countryCurrencyCodes.forEach((element) => {
currencyObj[element[0]] = element[1];
});
return currencyObj;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
22 changes: 20 additions & 2 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,7 +19,25 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let shoppingList = {};
let recipeName = recipe.name;
let missingIngredients = [];
console.log("recipe name ", recipeName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: Don't leave console.log lines in your solution if the exercise doesn't require them

let recipeIngredients = recipe.ingredients;
recipeIngredients.forEach((ingredient) => {
if (
pantry.cupboardContents.includes(ingredient) ||
pantry.fridgeContents.includes(ingredient)
) {
} else {
missingIngredients.push(ingredient);
}
if (missingIngredients.length > 0) {
shoppingList.items = missingIngredients;
shoppingList.name = recipeName;
}
});
return shoppingList;
}

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

let cashRegister = {
// write code here
}
orderBurger: function (balance) {
let newBalance = balance - MENU.burger;
if (newBalance >= 0) balance = newBalance;
return balance;
},
orderFalafel: function (balance) {
let newBalance = balance - MENU.falafel;
if (newBalance >= 0) balance = newBalance;
return balance;
},
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
52 changes: 18 additions & 34 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,30 @@ function convertScoreToGrade(score) {
- (Reminder: You must have run `npm install` one time before this will work!)
*/

/*
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");
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("a score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toEqual("B");
});
/*
Write a test that checks a score of 68 is grade C
*/

/*
Write a test that checks a score of 55 is grade 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");
});
60 changes: 54 additions & 6 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 @@ -49,43 +49,91 @@ function formatCourseworkResult(trainee) {
*/

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

test("Xin score of 63 is grade C", () => {
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:
Checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Mona",
score: 78
}
*/
test("Mona score of 78 is grade B", () => {
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:
Checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("Ali score of 49 is grade E", () => {
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:
Checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/
test("No trainee name supplied", () => {
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:
Checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("No trainee score supplied", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"],
};

expect(formatCourseworkResult(trainee)).toEqual(
"Error: Coursework percent is not a number!"
);
});
Loading