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 = "Spot"; // complete the code
let dogBreed = "Dalmatian"; // complete the code
Copy link

Choose a reason for hiding this comment

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

for these two you should access the dog object by doing dog.name or dog.breed


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 = "London"; // complete the code
Copy link

Choose a reason for hiding this comment

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

here you should use the alternate method of accessing object data, which would be capitalCities[myCountry]


console.log(myCapitalCity);

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)
Copy link

Choose a reason for hiding this comment

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

here you are expected to sort through this list of basketballTeam.topPlayers and then print each of the players on a new line. You can do that with array methods .sort() and .forEach()


/* EXPECTED RESULT

Expand Down
7 changes: 7 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ 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("After:")

console.log(capitalCities);

/* EXPECTED RESULT
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 @@ -17,6 +17,8 @@ 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 @@ -27,6 +29,11 @@ let student = {

// write code here

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


console.log(student);

/* EXPECTED RESULT
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 @@ -14,15 +14,15 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]); /// The car object does not have color property

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

let user = {
name: "Mira"
name: "Mira" ////. The object has only name property it does not have firstname property
};

sayHelloToUser(user);
Expand All @@ -31,7 +31,7 @@ sayHelloToUser(user);
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
return "My pet's name is Fluffy"; //. It should have return
},
};

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

// write code here
// Recipe 1
let recipe1 = {
title: "Mole",
servings: 2,
ingredients: ["cinnamon", "cumin", "cocoa"]
};

console.log(recipe1.title);
console.log(`Serves: ${recipe1.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe1.ingredients.length; i++) {
console.log(recipe1.ingredients[i]);
}

Copy link
Author

Choose a reason for hiding this comment

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

.forEch() is also the best mothod.
recipe1.ingredients.forEach(ingredient) => {
console.log(ingredient);
}

// Recipe 2
let recipe2 = {
title: "Bolani",
servings: 4,
ingredients: ["Gandana", "Dough", "oil", "salt", "green pepper"]
};

console.log(recipe2.title);
console.log(`Serves: ${recipe2.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe2.ingredients.length; i++) {
console.log(recipe2.ingredients[i]);
}

// Recipe 3
let recipe3 = {
title: "Borani Badinjan",
servings: 6,
ingredients: ["Ege plant", "tomato sauce", "oil", "black pepper", "turmeric", "garlic", "yogurt"]
};

console.log(recipe3.title);
console.log(`Serves: ${recipe3.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe3.ingredients.length; i++) {
console.log(recipe3.ingredients[i]);
}

// Recipe 4
let recipe4 = {
title: "Aye khanum",
servings: 8,
ingredients: ["beef mans", "carrot", "potatoes", "onion", "garlic", "oil", "tomato paste", "yogurt", "fresh coriander"]
};

console.log(recipe4.title);
console.log(`Serves: ${recipe4.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe4.ingredients.length; i++) {
console.log(recipe4.ingredients[i]);
}

// Recipe 5
let recipe5 = {
title: "Qabili",
servings: 6,
ingredients: ["rice", "oil", "onion", "carrots", "raisin", "salt", "lamb meat", "char masala"]
};

console.log(recipe5.title);
console.log(`Serves: ${recipe5.servings}`);
console.log("Ingredients:");
for (let i = 0; i < recipe5.ingredients.length; i++) {
console.log(recipe5.ingredients[i]);
}
Copy link

Choose a reason for hiding this comment

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

you can avoid repeating yourself here by moving these console.log and for loop into another function which takes a recipe as an argument. e.g. function logRecipe(recipe) { ... }

7 changes: 6 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
const lookup = {};
for(const [countryCode, currencyCode] of countryCurrencyCodes){
lookup[countryCode] = currencyCode;
}
return lookup
}
console.log(createLookup(COUNTRY_CURRENCY_CODES));

Copy link
Author

Choose a reason for hiding this comment

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

Or we can write the code as following:
function createLookup(countryCurrencyCodes) {
let currencyCodeLookup = {};

for (let countryCurrencyCode of countryCurrencyCodes) {
let countryCode = countryCurrencyCode[0];
let currencyCode = countryCurrencyCode[1];
currencyCodeLookup[countryCode] = currencyCode;
};

return currencyCodeLookup;
}

Copy link

Choose a reason for hiding this comment

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

I think your original solution is better, but this other solution is also nice and clear.

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand Down
10 changes: 8 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,13 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
const missingItems = recipe.ingredients.filter(ingredient =>{
return !pantry.fridgeContents.includes(ingredient)&& !pantry.cupboardContents.includes(ingredient);
});
return {
name: recipe.name,
items: missingItems,
}
}

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

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

Copy link
Author

Choose a reason for hiding this comment

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

const MENU = {
burger: 6.5,
falafel: 7.25,
};

let cashRegister = {
orderBurger: function(balance) {
let finalBalance = balance;
let isBalanceBigEnough = balance - MENU.burger >= 0;
if (isBalanceBigEnough) {
finalBalance = balance - MENU.burger;
}
return finalBalance;
},
orderFalafel: function(balance) {
let finalBalance = balance;
let isBalanceBigEnough = balance - MENU.falafel >= 0;
if (isBalanceBigEnough) {
finalBalance = balance - MENU.falafel;
}
return finalBalance;
},
};

Copy link

Choose a reason for hiding this comment

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

I like your original solution better here too

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
32 changes: 26 additions & 6 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

function convertScoreToGrade(score) {
let grade = null;

if (score >= 80) {
grade = "A";
} else if (score >= 70) {
Expand All @@ -35,41 +35,61 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83)).toBe("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("b score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toBe("B")
});
/*
Write a test that checks a score of 68 is grade C
Write a test that checks a score of 68 is grade C
*/
test("c score of 68 is grade C", () => {
expect(convertScoreToGrade(68)).toBe("C")
})

/*
Write a test that checks a score of 55 is grade D
*/
test("d score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toBe("D")
});

/*
Write a test that checks a score of 68 is grade C
*/
test("c score of 68 is grade C", () =>{
expect(convertScoreToGrade(68)).toBe("C")
});

/*
Write a test that checks a score of 55 is grade D
*/

test("d of score 55 is grade D", () =>{
expect(convertScoreToGrade(55)).toBe("D")
});
/*
Write a test that checks a score of 49 is grade E
*/
test("e of score 49 is grade E", ()=>{
expect(convertScoreToGrade(49)).toBe("E");
});

/*
Write a test that checks a score of 30 is grade E
*/
test("e score of 30 is grade E", ()=>{
expect(convertScoreToGrade(30)).toBe("E");
});

/*
Write a test that checks a score of 70 is grade B
*/
test("b score of 70 is grade B", ()=>{
expect(convertScoreToGrade(70)).toBe("B");
})
Loading