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

console.log(`${dogName} is a ${dogBreed}`);

Expand Down
8 changes: 4 additions & 4 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ let capitalCities = {
Do not use dot notation for this exercise!
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code

console.log(myCapitalCity);
// let myCountry = "UnitedKingdom";
// let myCapitalCity = capitalCities["UnitedKingdom"]; // complete the code
const myCountry = capitalCities["UnitedKingdom"]
console.log(myCountry);

/* EXPECTED RESULT

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let basketballTeam = {
*/

// write code here

console.log(basketballTeam.topPlayers.sort().join('\n'));

/* EXPECTED RESULT

Expand Down
6 changes: 6 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,12 @@ 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 @@ -27,6 +28,12 @@ let student = {

// write code here

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



console.log(student);

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

console.log(car["colour"]);
console.log(car["colour"]);// colour property or key hasn't defined any value.

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); //user.firstName property doesn't exit.
}

let user = {
name: "Mira"
};
let user = {
name: "Mira"
};

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
"My pet's name is Fluffy"; // getName function which is myPet object method doesn't have return keyword.
},
};

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
21 changes: 20 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,23 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here
function Recipe(title, serves, ingredients) {
this.title = title,
this.serves = serves,
this.ingredients = ingredients
}
// USE CONSTRCUTOR TO BUILD OBJECTS QUICKLY
let receipeOne = new Recipe("Stir Friedrice", 1, ["vege","oyster sauce","chicken","rice"]);
let receipeTwo = new Recipe("Stir Friednoodle", 2, ["vege","sweetchilli sauce","chicken","noodle"]);
let receipeThree = new Recipe("Chicken Curry", 3, ["onion","oil","chicken","spices"]);
let receipeFour = new Recipe("Lentils Soup", 4, ["lentils","onion","garlic"]);
let receipeFive = new Recipe("Chicken Salad", 5, ["lettuce","ceasar dressing","chicken","olive"]);

const recipes = [receipeOne, receipeTwo, receipeThree, receipeFour, receipeFive]

recipes.forEach((recipe) => {
console.log(recipe.title);
console.log(`Serve: ${recipe.serves}`);
console.log(`Ingredients: \n ${recipe.ingredients}`);
});
9 changes: 9 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];



function createLookup(countryCurrencyCodes) {
// write code here
let newObject = {};
for(let country of countryCurrencyCodes){
newObject[country[0]] = country[1];
}
return newObject;
//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
14 changes: 13 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ let pantry = {
cupboardContents: ["salt", "tinned tomatoes", "oregano"],
};


function createShoppingList(recipe) {
// write code here
const missingItems = [];
const allPantryContents = pantry.fridgeContents.concat(pantry.cupboardContents);

const missingIngredients = recipe.ingredients.filter(ingredient => {
return !(allPantryContents.includes(ingredient))
})

return {
name: recipe.name,
items: missingIngredients
}
}


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand Down
13 changes: 13 additions & 0 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ const MENU = {

let cashRegister = {
// write code here
orderBurger: function(balance){
if(balance >= MENU["burger"]){
return balance - MENU["burger"];
}
return balance;
},

orderFalafel: function(balance){
if(balance >= MENU["falafel"]){
return balance - MENU["falafel"];
}
return balance;
}
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down