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
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let dog = {
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 @@ -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
3 changes: 2 additions & 1 deletion 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let basketballTeam = {
*/

// write code here

let newArray=basketballTeam.topPlayers.sort();
newArray.forEach((x)=>{console.log(x)});

/* EXPECTED RESULT

Expand Down
6 changes: 5 additions & 1 deletion 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +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);

/* EXPECTED RESULT
Expand Down
6 changes: 4 additions & 2 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ 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
AND
exam score is above 60.
- Use bracket notation to change the value of hasPassed
*/

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

console.log(student);
Expand Down
6 changes: 3 additions & 3 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
For each example, can you explain why we are seeing undefined?
*/

// Example 1
// Example 1 color is not defined
let car = {
brand: "Ford",
yearsOld: 8,
};

console.log(car["colour"]);

// Example 2
// Example 2 name has been defined and not firstname
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}
Expand All @@ -27,7 +27,7 @@ let user = {

sayHelloToUser(user);

// Example 3
// Example 3 function does not have a callback.
let myPet = {
animal: "Cat",
getName: function() {
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 (getNames) {
console.log (`Student name: ${getNames}`)
}
}

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

// write code here
// write code here
let myRecipe = {
recipe1: {
title: "Oatcake",
serving: 4,
ingredients: [
"plain cheese",
"cream",
"stevia",
"vanilla essence",
],
},

recipe2: {
title: " White Chocolate Brownies",
serving: 4,
ingredients: ["eggs","white chocolate", "butter", "sugar"],
},

recipe3: {
title: "Curry",
serving: 4,
ingredients: ["onion", "masala", "tomatoes", "salt"],
},

recipe4: {
title: "biryani",
serving: 4,
ingredients: ["rice", "mix-vegetables", "masala", "olive oil"],
},

recipe5: {
title: "ice cream",
serving: 4,
ingredients: ["cream", "eggs", "sugar", "vanilla essence"],
},
};

function receipeKing(all) {
for(each in all) {
console.log(`${each}: ${all[each]}`);
}
}
receipeKing(myRecipe.recipe1);
receipeKing(myRecipe.recipe2);
receipeKing(myRecipe.recipe3);
receipeKing(myRecipe.recipe4);
receipeKing(myRecipe.recipe5);
1 change: 1 addition & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
return Object.fromEntries(countryCurrencyCodes);
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
17 changes: 17 additions & 0 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,24 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
const newShoppingList = {};
newShoppingList.name = recipe.name;
newShoppingList.items = [];
const pantryList = Object.values(pantry).flat();
for(ingredient of recipe.ingredients){
if (!pantryList.includes(ingredient)){
newShoppingList.items.push(ingredient);
}
}
return newShoppingList;
}
/*
function createShoppingList(recipe) {
return {
name: recipe.name,
items: recipe.ingredients.filter(ingredient => !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient))
}
} */

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

let cashRegister = {
// write code here
orderBurger : function (balance){
return balance >= MENU.burger ? balance - MENU.burger : balance;
},
orderFalafel: function (balance) {
return balance >= MENU.falafel ? balance - MENU.falafel : balance;
}
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
11 changes: 11 additions & 0 deletions 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ function countWords(string) {
const wordCount = {};

// write code here
if (string === ''){
return {}
}
string.split(' ').forEach(word =>{
if(wordCount[word] >= 1){
wordCount[word]++
}
else {
wordCount[word] =1
}
})

return wordCount;
}
Expand Down