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
13 changes: 6 additions & 7 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
*/

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.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 ="london"; // complete the code
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The goal here was to select the capital from the capitalCities object.

For example using capitalCities[myCountry] will access the member of the object based on the value stored in myCountry


console.log(myCapitalCity);

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

// write code here

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 @@ -10,7 +10,7 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
},
};

/*
Expand All @@ -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
4 changes: 2 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let student = {
- Add a property to the student object for attendance
- Set the value of attendance to 90
*/

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

/*
Expand All @@ -24,7 +24,7 @@ let student = {
exam score is above 60.
- Use bracket notation to change the value of hasPassed
*/

if(student.attendance>=90 && student.examScore>60){student["hasPassed"]=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.

Issue: The formatting of code here is not easily readable

// write code here

console.log(student);
Expand Down
7 changes: 5 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ let car = {
yearsOld: 8,
};

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

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

let user = {
Expand All @@ -32,7 +32,10 @@ let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
// return myPet
},

};

console.log(myPet.getName());
//the function does not have return
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
33 changes: 32 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here

let recipes = [
{ title: "Mole", serves: 2, ingredients: ["cinnamon", "cumin", "cocoa"] },
{ title: "Rice", serves: 5, ingredients: ["rice", "water", "oil"] },
{
title: "pizza",
serves: 3,
ingredients: ["flour", "onions", "meat", "garlic"],
},
{
title: "curry",
serves: 6,
ingredients: ["chicken", "onions", "mushrooms"],
},
{
title: "soup",
serves: 1,
ingredients: ["water", "flour", "peas", "mushroom"],
},
];

for (let i=0; i<recipes.length; i++) {
console.log(recipes[i].title);
console.log("Serves: ", recipes[i].serves);
console.log("Ingredients:");
for (let j = 0; j<recipes[i].ingredients.length; j++) {
console.log(recipes[i].ingredients[j]);
}
console.log(" ");
}

11 changes: 9 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,16 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
}
let currencyObject = {};

for (let aCountryCurrency of countryCurrencyCodes) {
const singleCountry = aCountryCurrency[0];
const singleCurrency = aCountryCurrency[1];
currencyObject[singleCountry] = singleCurrency;
}

return currencyObject;
}
/* ======= 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
19 changes: 19 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ let pantry = {
};

function createShoppingList(recipe) {
let shoppingList = {};
let theRecipeName = recipe.name;
let shoppingIngredients = [];

for (let ingredient of recipe.ingredients) {
let fridgeArray = pantry.fridgeContents;
let cupboardArray = pantry.cupboardContents;
if (
fridgeArray.includes(ingredient) ||
cupboardArray.includes(ingredient)
) {
} else {
shoppingIngredients.push(ingredient);
}
}
shoppingList["name"] = theRecipeName;
shoppingList["items"] = shoppingIngredients;
return shoppingList;

// write code here
}

Expand Down
17 changes: 16 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ const MENU = {
};

let cashRegister = {
// write code here
orderBurger:
function(balance)
{ if(balance >= MENU.burger){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The formatting and indentation of code here is not readable

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 =====
Expand Down
37 changes: 29 additions & 8 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)).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", () => {
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 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 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 49 is grade E
*/

test("a score of 49 is grade C", () => {
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");
});
53 changes: 49 additions & 4 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 Down Expand Up @@ -55,15 +55,33 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/
test("Xin score of 63 is 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:
{
name: "Mona",
score: 78
}
*/
test("Mona score of 78 is 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,19 +91,46 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/

test("Ali score of 49 is 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:
{
score: 90,
age: 29
}
*/

test("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:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
*/test("No trainee score", () => {
let trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
expect(formatCourseworkResult(trainee)).toEqual(
"Error: Coursework percent is not a number!"
)
})