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 //integer
};

/*
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; // 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 @@ -19,7 +19,7 @@ let capitalCities = {
let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code

console.log(myCapitalCity);
console.log(capitalCities[myCountry]);

/* EXPECTED RESULT

Expand Down
9 changes: 9 additions & 0 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ let basketballTeam = {

// write code here

function sortAlphabetically(basketballTeam) {
let newArray = [];
for (let alphabetical of basketballTeam.topPlayers ) {
newArray = basketballTeam.topPlayers.sort();
}
console.log(newArray.join('\r\n'));

}


/* EXPECTED RESULT

Expand Down
3 changes: 3 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,9 @@ let capitalCities = {
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.Peru = {name: "Lima", population: 9750000};

console.log(capitalCities);

Expand Down
5 changes: 4 additions & 1 deletion 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,6 +26,9 @@ let student = {
*/

// write code here
if(student.attendance >= 90 && student.examScore >= 60){
student['hasPassed'] = true;
}

console.log(student);

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

console.log(car["colour"]);
console.log(car["colour"]); //the key colour hasn't been defined

// Example 2
function sayHelloToUser(user) {
Expand All @@ -25,7 +25,7 @@ let user = {
name: "Mira"
};

sayHelloToUser(user);
sayHelloToUser(user); // the key that holds the user's name has a different name than the one passed in the function

// Example 3
let myPet = {
Expand All @@ -36,3 +36,4 @@ let myPet = {
};

console.log(myPet.getName());
// here we get undefined since we are not returning or printing out anything on the function.
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: ${name}`);
}
}

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

// write code here
let recipes ={
Flan : {
Serves: 6,
Ingredients: ["condensed milk", "eggs", "sugar", "milk", "vanilla extract"]

},
Paella: {
Serves: 8,
Ingredients:["rice", "chorizo", "pork", "chicken", "vegetable stock", "saffron", "turmeric", "onion", "garlic"]
},
Salad: {
Serves: 4,
Ingredients: ["tomatoes", "lettuce", "pears", "spinach", "rocket", "blue cheese", "feta cheese", "croutons", "dressing"]
},
Milkshake: {
Serves: 4,
Ingredients: ["mango", "strawberries", "vanilla ice cream", "milk"]
},
Brownies: {
Serves: 6,
Ingredients: ["cocoa powder", "butter", "dark chocolate", "sugar", "eggs"]
}

};

Object.entries(recipes).forEach(([name, recipe]) => {
console.log(name);
console.log(`Serves: ${recipe.Serves}`);
console.log(`Ingredients:`);
for(let ingredient of recipe.Ingredients){
console.log(ingredient);
}
})
13 changes: 12 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
const object = {};

for(let item = 0; item < countryCurrencyCodes.length; item++){
const[country, currency] = countryCurrencyCodes[item]; //destructuring the array
object[country] = currency;
}


return object;
}

// let obj['country'] = currency;


/* ======= 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: 17 additions & 2 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

The createShoppingList function should return an object with two properties:
- "name" of the recipe, which is a string,
- "items", which is an arry of the missing ingredients that need to be on the shopping list
- "items", which is an array of the missing ingredients that need to be on the shopping list
*/

let pantry = {
Expand All @@ -19,7 +19,22 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let listToBuy = {};
let recipeName = recipe['name'];
let ingredients = recipe['ingredients'];
let missingIngredients = [];
ingredients.forEach(item => {
if(!pantry.fridgeContents.includes(item) && !pantry.cupboardContents.includes(item)) {
missingIngredients.push(item);
listToBuy['name']= recipeName;
listToBuy['items'] = missingIngredients;
}

});

return listToBuy;


}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
18 changes: 17 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ const MENU = {
};

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 =====
Expand Down
32 changes: 29 additions & 3 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,67 @@ 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");
});