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

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 // complete the code

console.log(myCapitalCity);

Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ let basketballTeam = {
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/
let topPlayers = basketballTeam.topPlayers;
topPlayers.sort();

for (let i = 0; i < topPlayers.length; i++) {
console.log(topPlayers[i]);
}

// write code here

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


capitalCities.UnitedKingdom.population=898000;
capitalCities.China.population=21500000;
capitalCities.Peru = { name: "Lima", population: 9750000 };
/*
Using dot notation:
- Change the value of UnitedKingdom's capital city population to 8980000.
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 @@ -16,7 +16,7 @@ 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 @@ -26,7 +26,9 @@ let student = {
*/

// write code here

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

/* EXPECTED RESULT
Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
For each example, can you explain why we are seeing undefined?
*/

// Example 1
// Example 1( car object does not have a property called colour.)
let car = {
brand: "Ford",
yearsOld: 8,
};

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

// Example 2
// Example 2( because the sayHelloToUser function tries to access the firstName property of the user object, which does not exist, so it returns undefined.)
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}
Expand All @@ -27,7 +27,7 @@ let user = {

sayHelloToUser(user);

// Example 3
// Example 3(getName method will return the string "My pet's name is Fluffy" when called, and that will be logged to the console.)
let myPet = {
animal: "Cat",
getName: function() {
Expand Down
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}`);
}
}

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

// write code here
// write code here
let recipe={
title: "adana kebab",

Serves: 2,
Ingredients:["cinnamon", "cumin" ,"cocoa"]

}
console.log(recipe.title);
console.log(`Serves: ${recipe.Serves}`);
console.log(recipe.Ingredients.join("/n"));
8 changes: 7 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ const COUNTRY_CURRENCY_CODES = [

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

}
return result
}

//console.log(createLookup(COUNTRY_CURRENCY_CODES))
/* ======= 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 Down
23 changes: 20 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,32 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
const result = {
name: recipe.name,
items: [],
};
for (let i = 0; i < recipe.ingredients.length; i++) {
if (
!pantry.fridgeContents.includes(recipe.ingredients[i]) &&
!pantry.cupboardContents.includes(recipe.ingredients[i])
) {
result.items.push(recipe.ingredients[i]);
}
}
return result;
}

/* 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`
- To run all exercises/tests in the mandatory folder, run `npm test`
- (Reminder: You must have run `npm install` one time before this will work!)
*/

test("createShoppingList works for pancakes recipe", () => {
test("createShoppingList works for pancakes recipe", () => {
let recipe1 = {
name: "pancakes",
ingredients: ["flour", "salt", "milk", "eggs", "vegetable oil"],
Expand All @@ -50,4 +67,4 @@ test("createShoppingList works for margherita pizza recipe", () => {
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
});
});
});
6 changes: 4 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const MENU = {

let cashRegister = {
// write code here
}
orderBurger: (balance) => (balance >= MENU.burger ? balance - MENU.burger : balance),
orderFalafel: (balance) => (balance >= MENU.falafel ? balance - MENU.falafel : balance)
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand All @@ -47,4 +49,4 @@ test("orderBurger will not subtract from balance if balance is too low", () => {
test("orderFalafel will not subtract from balance if balance is too low", () => {
let balance = 7.24;
expect(cashRegister.orderFalafel(balance)).toEqual(7.24);
});
});
28 changes: 25 additions & 3 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,63 @@ 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), "Z");
//});
/*
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");
});
50 changes: 49 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 All @@ -31,6 +31,7 @@ function convertScoreToGrade() {
function formatCourseworkResult(trainee) {
if (!trainee.name) {
return "Error: No trainee name!";
// trainee.name = "Trainee"; // had to assign this because js and test dont match on purpose
}
let traineeName = trainee.name;

Expand All @@ -55,6 +56,17 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("Trainee's score", () => {
let trainee1 = {
name: "Xin",
score: 63
};

expect(formatCourseworkResult(trainee1)).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 +75,16 @@ function formatCourseworkResult(trainee) {
score: 78
}
*/
test("Trainee's score", () => {
let trainee1 = {
name: "Mona",
score: 78,
};

expect(formatCourseworkResult(trainee1)).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 +95,16 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("Trainee's score", () => {
let trainee1 = {
name: "Ali",
score: 49,
};

expect(formatCourseworkResult(trainee1)).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 +113,13 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
test("Trainee's score", () => {
let trainee1 = {
score: 90,
};

expect(formatCourseworkResult(trainee1)).toEqual("Error: No trainee name!");
});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -89,3 +128,12 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("Trainee's score", () => {
let trainee1 = {
name: "Aman",
};

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