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.breed; // complete the code
let dogBreed = dog.name; // 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[myCountry]; // complete the code

console.log(myCapitalCity);

Expand Down
9 changes: 7 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ let basketballTeam = {
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/
function sortedPopPlayers (basketballTeam) {
const sortedPlayers = basketballTeam.topPlayers.sort()
return sortedPlayers.forEach(element => {
console.log(element)
});
}

// write code here

sortedPopPlayers(basketballTeam)

/* 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,8 +22,13 @@ 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;

// capitalCities.peru = { name: "lima", population: 9750000}
console.log(capitalCities);

Choose a reason for hiding this comment

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

instead of adding an empty variable and then adding values to it you can add the new country and its properties in one statement
capitalCities.peru = { name: "Lima", population: 9750000 };

Copy link
Author

Choose a reason for hiding this comment

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

Thanks

/* EXPECTED RESULT
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 @@ -15,8 +15,7 @@ let student = {
- Set the value of attendance to 90
*/

// write code here

student["attendence"] = 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 @@ -25,7 +24,9 @@ let student = {
- Use bracket notation to change the value of hasPassed
*/

// write code here
if(student.examScore > 60 && student.attendence >= 90){
student.hasPassed = true
Copy link

@mira-shukla mira-shukla Apr 14, 2023

Choose a reason for hiding this comment

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

here bracket notation is meant to be used instead of the . notation

}

console.log(student);

Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let car = {
};

console.log(car["colour"]);
// property "colur" doesn't exist

// Example 2
function sayHelloToUser(user) {
Expand All @@ -26,7 +27,7 @@ let user = {
};

sayHelloToUser(user);

//the function sayHelloToUser trying eccess to non-existent property in an object "user"
// Example 3
let myPet = {
animal: "Cat",
Expand All @@ -36,3 +37,4 @@ let myPet = {
};

console.log(myPet.getName());
//the function getName does'n access to any prorerty inside of an object
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,11 +8,13 @@
*/

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

}
}

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel
Expand Down
15 changes: 14 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@

You should write and log at least 5 recipes
*/
let TheRecipeCard = {}
TheRecipeCard.title = "Items mix :D"
TheRecipeCard.Serves = 2;

// write code here

TheRecipeCard.Ingredients = []

let ingr = ["item1","item2","item3","item4"]

ingr.forEach(element => {
TheRecipeCard.Ingredients.push(element)
})
console.log(TheRecipeCard.title)
console.log(`Serves: ${TheRecipeCard.Serves}`)
TheRecipeCard.Ingredients.map(property => {console.log(property)})
8 changes: 6 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let obj = {};
for(const [code, currency] of countryCurrencyCodes){
obj[code] = currency;
}
return obj
// return Object.fromEntries(countryCurrencyCodes);
}

/* ======= 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
17 changes: 16 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let missingIngredients = {
name: 0,
items: [],
}

missingIngredients.items = recipe.ingredients.filter(element => !pantry.fridgeContents.includes(element) && !pantry.cupboardContents.includes(element));
missingIngredients.name = recipe.name;

return missingIngredients;
}


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`
Expand Down
12 changes: 11 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ const MENU = {
};

let cashRegister = {
// write code here
orderBurger (balance){

Choose a reason for hiding this comment

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

here the balance is actually the remaining balance so at some point we would not have any remaining balance left

if(balance >= MENU.burger){
return balance - MENU.burger
} else return balance
},
orderFalafel(balance){
if(balance >= MENU.falafel){
return balance - MENU.falafel
} else return balance

}
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
36 changes: 26 additions & 10 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

function convertScoreToGrade(score) {
let grade = null;
let grade = "null";

if (score >= 80) {
grade = "A";
Expand Down Expand Up @@ -35,41 +35,57 @@ 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
*/

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)).toBe("B")
});
/*
Write a test that checks a score of 68 is grade C
*/

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

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

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

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

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

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

46 changes: 41 additions & 5 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 All @@ -34,7 +34,7 @@ function formatCourseworkResult(trainee) {
}
let traineeName = trainee.name;

if (typeof trainee.score != "number") {
if (typeof trainee.score !== "number") {
return "Error: Coursework percent is not a number!";
}
let traineeGrade = convertScoreToGrade(trainee.score);
Expand All @@ -55,37 +55,73 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/

test("trainee with score 63 has grade C", ()=>{
const trainee = {
name: "Xin",
score: 63,
}
expect(formatCourseworkResult(trainee)).toBe("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("trainee with score 78 has grade B", ()=>{
const trainee = {
name: "Mona",
score: 78,
}
expect(formatCourseworkResult(trainee)).toBe("Mona's coursework was marked as grade B.");
})

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Ali",
score: 49,
score: 63,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("trainee with score 63 has grade C", ()=>{
const trainee = {
name: "Ali",
score: 63,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
}
expect(formatCourseworkResult(trainee)).toBe("Ali's coursework was marked as grade C.");
})

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
age: 29,
}
*/

test("trainee with score 90 has grade A", ()=>{
const trainee = {
score: 90,
age: 29,
}
expect(formatCourseworkResult(trainee)).toBe("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("trainee with no score", ()=>{
const trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
expect(formatCourseworkResult(trainee)).toBe("Error: Coursework percent is not a number!");
});
Loading