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

let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
breed: "Dalmatian", // string.
name: "Spot", // string.
isHungry: true, // bolean.
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;
dogName = "Scoobydo"; // complete the code
let dogBreed;
dogBreed = "Dalmatian"; // complete the code

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well-done, Nice coding


/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
7 changes: 3 additions & 4 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let capitalCities = {
UnitedKingdom: "London",
China: "Beijing",
Peru: "Lima"
Peru: "Lima",
};

/*
Expand All @@ -17,12 +17,11 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

/* EXPECTED RESULT

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice1

London

*/
*/
5 changes: 3 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ let basketballTeam = {
*/

// write code here

let sortedNames = basketballTeam.topPlayers.sort();
console.log(basketballTeam.topPlayers);

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
15 changes: 11 additions & 4 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
population: 21500000,
},
Peru: {
name: "Lima",
population: 9750000,
},
};

capitalCities.UnitedKingdom.population = 8980000;

/*
Using dot notation:
- Change the value of UnitedKingdom's capital city population to 8980000.
- Add the property for population to China's capital city and set the value to 21500000.
- Change the value of UnitedKingdom's capital city population to 8980000. ------ done
- Add the property for population to China's capital city and set the value to 21500000. ------done
- Add the country "Peru" to capitalCities object.
- Add a name of "Lima" to Peru's capital city.
- Add a population of 9750000 to Peru's capital city.
Expand All @@ -34,4 +41,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

*/
*/
14 changes: 12 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let student = {
name: "Reshma Saujani",
examScore: 65,
hasPassed: false
hasPassed: false,
};

/*
Expand All @@ -17,6 +17,12 @@ let student = {

// write code here

student.attendance = 90;

console.log(student["attendance"]);

// student.attendance = 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 @@ -27,6 +33,10 @@ let student = {

// write code here

if (student.attendance <= 90 && student.examScore < 60) {
console.log(`${student} have passed`);
}

console.log(student);

/* EXPECTED RESULT
Expand All @@ -38,4 +48,4 @@ console.log(student);
attendance: 90
}

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

console.log(car["colour"]);
console.log(car["colour"]); // beacuse colour is not defined in car properry.

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

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

sayHelloToUser(user);
sayHelloToUser(user); // user have property of name not first name.

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
getName: function () {
"My pet's name is Fluffy";
},
};

console.log(myPet.getName());
console.log(myPet.getName()); // this function is not returning anything.
8 changes: 6 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

let student = {
// write code here
}

getName: function (name) {
console.log(`student name: ${name}`);
},
};

student.getName("Daniel");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work


/* EXPECTED RESULT

Student name: Daniel

*/
*/
53 changes: 52 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,55 @@
You should write and log at least 5 recipes
*/

// write code here
// write code here

let recipe1 = {
tittle: "Pancakes",
serves: 2,
ingredients: [
"milk",
"butter",
"egg",
"sugar",
"flour",
"baking powder",
"salt",
],
};

let recipe2 = {
tittle: "Pizza",
serves: 4,
ingredients: ["flour", "yeast", "mozarella", "totmato pure", "oil"],
};

let recipe3 = {
title: "Mole",
serves: 4,
ingredients: ["cinnamon", "cumin", "cocoa"],
};

let recipe4 = {
title: "Pretizel",
serves: 4,
ingredients: ["yeast", "sugar", "salt", "water", "butter"],
};

let recipe5 = {
title: "Ice-cream",
serves: 2,
ingredients: [
"milk",
"cream",
"melted chocolate",
"sugar",
"cocoa powder",
"additional mix-ins",
],
};

console.log(recipe1);
console.log(recipe2);
console.log(recipe3);
console.log(recipe4);
console.log(recipe5);
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,6 +19,12 @@ const COUNTRY_CURRENCY_CODES = [

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

for (const countryCurrencyCode of countryCurrencyCodes) {
showCountryCurrencyCodes[countryCurrencyCode[0]] = countryCurrencyCode[1];
}
return showCountryCurrencyCodes;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +40,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
28 changes: 25 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
const newRecipe = {
name: recipe.name,
items: [],
};

for (const item of recipe.ingredients) {
if (
!pantry.fridgeContents.includes(item) &&
!pantry.cupboardContents.includes(item)
)
newRecipe.items.push(item);
}
// return { name: recipe.name, items: newRecipe.items };
console.log(newRecipe);
return newRecipe;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -43,11 +58,18 @@ test("createShoppingList works for pancakes recipe", () => {
test("createShoppingList works for margherita pizza recipe", () => {
let recipe2 = {
name: "margherita pizza",
ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"],
ingredients: [
"flour",
"salt",
"yeast",
"tinned tomatoes",
"oregano",
"mozarella",
],
};

expect(createShoppingList(recipe2)).toEqual({
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
items: ["flour", "yeast", "mozarella"],
});
});
});
20 changes: 19 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,25 @@ const MENU = {

let cashRegister = {
// write code here
}

orderBurger: function (balance) {
let newBalance = 0;

if (balance >= 6.5) {
newBalance = balance - MENU.burger;
} else newBalance = balance;
return newBalance;
},

orderFalafel: function (balance) {
let newBalance = 0;

if (balance >= 7.25) {
newBalance = balance - MENU.falafel;
} else newBalance = balance;
return newBalance;
},
};

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
Loading