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
10 changes: 9 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,15 @@ let basketballTeam = {
- console.logs the name of each player on a new line
*/

// write code here
function bestPlayers() {
let topPlayersNames = basketballTeam.topPlayers
topPlayersNames = topPlayersNames.sort()
console.log(topPlayersNames)

}

bestPlayers();



/* EXPECTED RESULT
Expand Down
5 changes: 5 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ 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);

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

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

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand All @@ -26,6 +27,12 @@ let student = {
*/

// write code here
function isPassed (attendance, examScore) {
if ((attendance >= 90) && (examScore > 60)) {
return true;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you could possibly write like:
function isPassed (attendance, examScore) {
return attendance >= 90 && examScore > 60
}
'return' returns boolean!

}
}
student ["hasPassed"] = isPassed(90, 65);

console.log(student);

Expand Down
10 changes: 5 additions & 5 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]); // the property colour is not defined in the object car

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

let user = {
name: "Mira"
};

sayHelloToUser(user);
sayHelloToUser(user); // in this example the object user has the property name and not firstName as used in the function sayHelloToUser

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

console.log(myPet.getName());
console.log(myPet.getName()); // the function in the property getName should has a return statement
5 changes: 4 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,10 @@
*/

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

}

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

// write code here
// write code here

let favRecipe1 = {
name: "salads",
servings: "services: " + 2,
ingredients: ["tomato", "cucamber", "lemon", "avocado", "sweetcorn", "eggs"]
}
function ingredientPrinting(favRecipe1) {
console.log("ingredients: ")
for ( let i = 0; i < favRecipe1.ingredients.length; i++) {
console.log(favRecipe1.ingredients[i]);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Nicely written function



console.log(favRecipe1.name);
console.log(favRecipe1.servings);
ingredientPrinting(favRecipe1);

15 changes: 13 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let key;
let value;
let countryCurrencyObject = {};
for (let i = 0; i < countryCurrencyCodes.length; i++) {
key = countryCurrencyCodes[i][0];
value = countryCurrencyCodes[i][1];
countryCurrencyObject[key] = value;
}
return countryCurrencyObject
}

console.log(createLookup(COUNTRY_CURRENCY_CODES))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Nice!

Consider: You could consider to check a .forEach
https://www.w3schools.com/jsref/jsref_foreach.asp
const lookup = {};
countryCurrencyCodes.forEach(([country, currency]) => {
lookup[country] = currency;
});
return lookup;
}

const lookup = createLookup(COUNTRY_CURRENCY_CODES);
console.log(lookup);


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand All @@ -34,4 +44,5 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});

25 changes: 23 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,28 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
}
let shoppingList = {};
shoppingList.name = recipe.name;
shoppingList.items = [];
for (let element of recipe.ingredients) {
if (pantry.fridgeContents.includes(element)) {
shoppingList.items = shoppingList.items
} else if (pantry.cupboardContents.includes(element)) {
shoppingList.items = shoppingList.items
} else {
shoppingList.items.push(element)
}
}
return shoppingList
}
// let recipe1 = {
// name: "pancakes",
// ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"],
// };
// console.log(createShoppingList(recipe1));




/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand All @@ -34,6 +54,7 @@ test("createShoppingList works for pancakes recipe", () => {
ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"],
};


expect(createShoppingList(recipe1)).toEqual({
name: "pancakes",
items: ["flour", "eggs", "vegetable oil"],
Expand Down
19 changes: 17 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ const MENU = {
burger: 6.5,
falafel: 7.25,
};

let balance = 6.5
let cashRegister = {
// write code here
orderBurger: function(balance) {
if (balance >= MENU.burger) {
balance = balance - MENU.burger
}
return balance;
},
orderFalafel: function(balance) {
if (balance >= MENU.falafel) {
balance = balance - MENU.falafel
}
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
27 changes: 24 additions & 3 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,62 @@ 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", () => {
/* 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
*/
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")
});

/*
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")
});
43 changes: 42 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,9 @@
trainee has completed.
*/

function convertScoreToGrade() {
const { TestScheduler } = require("jest");

function convertScoreToGrade(score) {
let grade = null;

if (score >= 80) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment: Well done!

Expand Down Expand Up @@ -55,6 +57,13 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("Xin's coursework was marked as 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:
Expand All @@ -63,6 +72,13 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/
test("Mona's coursework was marked as 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:
Expand All @@ -73,6 +89,15 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("Ali's coursework was marked as 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:
Expand All @@ -81,6 +106,13 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
test("no trainee name is equal to Error: No trainee 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 +121,12 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("no trainee score is equal to Error: Coursework percent is not a number!", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databasese"],

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

4 changes: 2 additions & 2 deletions 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

function countWords(string) {
const wordCount = {};

// write code here


return wordCount;
}
Expand Down