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;
let dogBreed = dog.breed;

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

Expand Down
5 changes: 3 additions & 2 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ let capitalCities = {
Do not use dot notation for this exercise!
*/

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


console.log(myCapitalCity);

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

// write code here

let newBasketballTeam = basketballTeam.topPlayers.sort();

for ( const players of newBasketballTeam){
console.log(players);
}



/* 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 @@ -12,6 +12,12 @@ let capitalCities = {
name: "Beijing",
}
};
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCitie.peru = {
name: "Lima",
population: 9750000
};

/*
Using dot notation:
Expand All @@ -22,7 +28,6 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here

console.log(capitalCities);

Expand Down
11 changes: 10 additions & 1 deletion 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ 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,7 +30,13 @@ let student = {

// write code here

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



console.log(student);

/* EXPECTED RESULT

Expand Down
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 @@ -7,8 +7,10 @@
- console.logs a message that says: "Student name: " followed by the name given as an argument
*/

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

}

student.getName("Daniel");
Expand Down
13 changes: 12 additions & 1 deletion 2-mandatory/1-recipes.js
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 = {
title : "kotlet",
serving : 2,
ingredients : ["onion", "potato", "meet", "spices"]

};
console.log(recipe.title);
console.log(recipe.serving);
for(const item of recipe.ingredients){
console.log(item);
}
9 changes: 7 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ const COUNTRY_CURRENCY_CODES = [
["NG", "NGN"],
["MX", "MXN"],
];

let newObject = {};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Check what would happen to 'newObject' if you call createLookup() twice.

function createLookup(countryCurrencyCodes) {
// write code here
for (let item of COUNTRY_CURRENCY_CODES) {
let countryCode = item[0];
newObject[countryCode] = item[1];
}

return newObject;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
16 changes: 14 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ let pantry = {
fridgeContents: ["butter", "milk"],
cupboardContents: ["salt", "tinned tomatoes", "oregano"],
};

function createShoppingList(recipe) {
// write code here
const missingItems = {
name: recipe.name,
items: [],
};
for (const ingredient of recipe.ingredients) {
if (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
) {
missingItems.items.push(ingredient);
}
}
return missingItems;
}


/* ======= 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
20 changes: 18 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@ const MENU = {
};

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

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

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
22 changes: 18 additions & 4 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,31 @@ 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", () => {
/* Remove the .skip above, then write the test body. */
expect(convertScoreToGrade(71)).toEqual("B");
});
/*
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
Expand All @@ -65,11 +72,18 @@ test.skip("a score of 71 is grade B", () => {
/*
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");
});
50 changes: 47 additions & 3 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
For this exercise, the function has been written for you and you need to write
the tests.

This function takes a trainee parameter that is an object. The object
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tests are all ok but read this again and check the function convertScoreToGrade() again.

This function takes a that is an object. The object
contains: name (which represents the trainee's name) and score (which
represents the mark given to the trainee's coursework).

Expand Down Expand Up @@ -55,15 +55,31 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/

test("a score of 63 is grade C", () => {
const 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:
{
name: "Mona",
score: 78
}
*/

test("a score of 78 is grade B", () => {
const 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:
{
Expand All @@ -73,19 +89,47 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("the score of Ali is E", () => {
const 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:
{
score: 90,
age: 29
}
*/
test("there is 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:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("there is no score", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"],
};

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