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
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["UnitedKingdom"];

console.log(myCapitalCity);

Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ let basketballTeam = {
- console.logs the name of each player on a new line
*/

// write code here
let sortedTeam = basketballTeam.topPlayers.sort();

console.log(sortedTeam);


/* 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 = {
name: "Lima",
population: 9750000,
};

console.log(capitalCities);

Expand Down
6 changes: 4 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let student = {
- 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 +25,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
4 changes: 4 additions & 0 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ let car = {
brand: "Ford",
yearsOld: 8,
};
// the is no object for colour

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

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}
// the object name not related to firstName to console user name and function working.

let user = {
name: "Mira"
Expand All @@ -35,4 +37,6 @@ let myPet = {
},
};

// uncompleted function no return or doing any thing

console.log(myPet.getName());
4 changes: 3 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

let student = {
// write code here
getname: function (name){
console.log("Student name: ");
}
}

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

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 👍

// write code here
let banoffee = {
title: "Banoffee",
servings: 7,
ingredients: [
"bananas",
"biscuits",
"butter",
"condensed milk",
"sugar",
"cream",
],
};
console.log(banoffee.title);
console.log("Serves: " + banoffee.servings);
console.log("Ingredients:");
// for (let i = 0; i < banoffee.ingredients.length; i++) {
// console.log(banoffee.ingredients[i]);
// }
// review solution

banoffee.ingredients.forEach((el) => {
console.log(el);
});
32 changes: 29 additions & 3 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,36 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me! I like your use of the forEach array method here.

function createLookup(countryCurrencyCodes) {
// write code here
function createLookup(countryCurrencyCodes){
let resultLookup = {};
countryCurrencyCodes.forEach(([el, curr]) => {
resultLookup[el] = curr
});
return resultLookup
}


//------>>> another solution

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

//------>>> another solution

// function createLookup(COUNTRY_CURRENCY_CODES) {
// const country = new Map(COUNTRY_CURRENCY_CODES);
// const obj = Object.fromEntries(country);
// return obj
// }



/* ======= 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 All @@ -34,4 +60,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
21 changes: 19 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,26 @@ let pantry = {
cupboardContents: ["salt", "tinned tomatoes", "oregano"],
};



function createShoppingList(recipe) {
// write code here
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The implementation looks good to me. For an extra challenge - can you implement this using the filter array method?

let shoppingList = {};
shoppingList.items =[];
shoppingList.name = recipe.name
// check ingredients
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
16 changes: 15 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@ const MENU = {
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perfect!

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 =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
31 changes: 27 additions & 4 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,64 @@ 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
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These tests look good 👍

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. */
});
/*

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

test("a score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toBe("D");
/*
Write a test that checks a score of 55 is grade D
*/
});

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

test("a score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toBe("D");
/*
Write a test that checks a score of 55 is grade D
*/
});

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

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

/*
test("a score of 70 is grade B", () => {
expect(convertScoreToGrade(70)).toBe("B");
/*
Write a test that checks a score of 70 is grade B
*/
});
46 changes: 45 additions & 1 deletion 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 @@ -55,6 +55,16 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("Trainee Xin, score of 63",() =>{
let trainee = {
name: "Xin",
score: 63,
};
expect(formatCourseworkResult(trainee)).toEqual(
`${trainee.name}'s coursework was marked as grade C.`
);
});


/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -63,6 +73,12 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/
test(`trainee Mona, score is 78`,() => {
let trainee ={ name:`Mona`, score: 78,}
expect(formatCourseworkResult(trainee)).toEqual(
`${trainee.name}'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 +89,17 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test(`trainee Ali , score is 49`, () => {
let trainee = {
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"],
};
expect(formatCourseworkResult(trainee)).toEqual(
`${trainee.name}'s coursework was marked as grade E.`
);
})

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -81,6 +108,14 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
test("Trainee , score of 90", () => {
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 +124,12 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These tests look good - but have a think about the best way to name the tests.
Imagine we make a code change which makes this test fail. In the test output - we will see Trainee Aman, score of but this doesn't really tell us which part of the code is broken. Maybe a better name for this is should return error when coursework score is missing (just an example).

test("Trainee Aman, score of ", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"],
};
expect(formatCourseworkResult(trainee)).toEqual(
`Error: Coursework percent is not a number!`
);
});