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
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let basketballTeam = {
address: "1901 W Madison St",
},
};
basketballTeam.topPlayers.sort().forEach(x =>{console.log(x)});

/*
Write code that
Expand All @@ -22,11 +23,10 @@ let basketballTeam = {

// write code here


/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
8 changes: 5 additions & 3 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ let capitalCities = {
},
China: {
name: "Beijing",
}
},
};

/*
Using dot notation:
- Change the value of UnitedKingdom's capital city population to 8980000.
Expand All @@ -23,6 +22,9 @@ let capitalCities = {
*/

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

console.log(capitalCities);

Expand All @@ -34,4 +36,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

*/
*/
7 changes: 5 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 @@ -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 @@ -26,6 +27,8 @@ let student = {
*/

// write code here
student.hasPassed =
student.attendance >= 90 && student.examScore > 60 ? true : false;

console.log(student);

Expand All @@ -38,4 +41,4 @@ console.log(student);
attendance: 90
}

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

console.log(car["colour"]);
console.log(car["colour"]); // color property not defined in car object.

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); //firstName property is not defined in user object instead we need to use name property
}

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

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
getName: function () {// return keyword is missing
"My pet's name is Fluffy";
},
};
Expand Down
5 changes: 4 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,10 @@
*/

let student = {
// write code here
// write code here`
getName: function(name){
console.log(`Student name: ${name}`)
}
}

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

// write code here
// write code here


let favoriteRecipe = {
recipe1: {
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"],
},
recipe2: {
title: "Pizza Margherita XL",
servings: 4,
ingredients: ["strong bread flour", "yeast", "salt", "olive", "tomato"],
},
recipe3: {
title: "Pancake",
servings: 3,
ingredients: ["egg", "milk", "flour", "butter", "salt", "baking powder"],
},
recipe4: {
title: "Mango Lassi",
servings: 2,
ingredients: ["mango", "plain yogurt", "milk", "honey", "cardamom", "ice"],
},
recipe5: {
title: "Kebab",
servings: 1,
ingredients: ["lamb", "tomato", "salt", "lime", "garlic"],
},
display: function (recipe) {
let res = `${this[recipe].title}\nServes: ${this[recipe].servings}\nIngredients:\n`;
for (let i = 0; i < this[recipe].ingredients.length; i++)
res += this[recipe].ingredients[i] + "\n";
return res;
},
};

for (let i = 1; i < Object.keys(favoriteRecipe).length; i++)
console.log(favoriteRecipe.display("recipe" + i));
9 changes: 7 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ const COUNTRY_CURRENCY_CODES = [
["NG", "NGN"],
["MX", "MXN"],
];

function createLookup(countryCurrencyCodes) {
// write code here
let res = {};
for (let i = 0; i < countryCurrencyCodes.length; i++)
res[countryCurrencyCodes[i][0]] = countryCurrencyCodes[i][1];

return res;
}
console.log(createLookup(COUNTRY_CURRENCY_CODES));

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand All @@ -34,4 +39,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
34 changes: 30 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,27 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
// write code here`
return {
name: recipe.name,
items: recipe.ingredients.filter(
(x) => !pantry.fridgeContents.concat(pantry.cupboardContents).includes(x)
),
};
}
console.log(
createShoppingList({
name: "margherita pizza",
ingredients: [
"flour",
"salt",
"yeast",
"tinned tomatoes",
"oregano",
"mozarella",
],
})
);

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand All @@ -43,11 +62,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"],
});
});
});
9 changes: 8 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ 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;``
},
};
console.log(cashRegister.orderBurger(6.4));

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
32 changes: 28 additions & 4 deletions 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@ function countWords(string) {
const wordCount = {};

// write code here
const punctuation = [",", ".", "'", '"', ":"];
if (string !== "") {
let words = string.split(" ");

for (let i = 0; i <= words.length; i++) {
i = 0;
let count = 0;
let word = words[i];
for (let j = 0; j < words.length; j++) {
if (word === words[j]) count++;
}
punctuation.some((p) => word.includes(p))
? (wordCount[`${word}`] = count)
: (wordCount[word] = count);
while (words.indexOf(word) !== -1) words.splice(words.indexOf(word), 1);
}
}
return wordCount;
}

Expand All @@ -46,17 +62,25 @@ test("Code works for a small string", () => {
});

test("A string with, some punctuation", () => {
expect(countWords("A string with, some punctuation")).toEqual(
{ A: 1, string: 1, "with,": 1, some: 1, punctuation: 1 }
);
expect(countWords("A string with, some punctuation")).toEqual({
A: 1,
string: 1,
"with,": 1,
some: 1,
punctuation: 1,
});
});

test("Empty string", () => {
expect(countWords("")).toEqual({});
});

test("Example task string", () => {
expect(countWords("you're braver than you believe, stronger than you seem, and smarter than you think")).toEqual({
expect(
countWords(
"you're braver than you believe, stronger than you seem, and smarter than you think"
)
).toEqual({
"you're": 1,
and: 1,
"believe,": 1,
Expand Down