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
8 changes: 4 additions & 4 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
happiness: 6,
};

/*
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}`);

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
6 changes: 3 additions & 3 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,12 @@ let capitalCities = {
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code
let myCapitalCity = capitalCities[myCountry]; // complete the code

console.log(myCapitalCity);

/* EXPECTED RESULT

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

const basketballPlayers = basketballTeam.topPlayers.sort();
console.log(basketballPlayers);

/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

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

/*
Expand All @@ -23,6 +23,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 +37,4 @@ console.log(capitalCities);
Peru: { name: "Lima", population: 9750000 }
}

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

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

console.log(student);

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

*/
*/
10 changes: 8 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,29 @@ let car = {

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

//There is no (car : color) as an object properties.

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

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

sayHelloToUser(user);

//The object properties is name not firstName.

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

console.log(myPet.getName());

// the getName function does not have return.
7 changes: 5 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,15 @@

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

*/
*/
30 changes: 29 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,33 @@

You should write and log at least 5 recipes
*/
// write code here

// write code here
let recipes = [
{ title: "Mole", serves: 2, ingredients: ["cinnamon", "cumin", "cocoa"] },
{ title: "Rice", serves: 5, ingredients: ["rice", "water", "oil"] },
{
title: "pizza",
serves: 3,
ingredients: ["flour", "onions", "meat", "garlic"],
},
{
title: "curry",
serves: 6,
ingredients: ["chicken", "onions", "mushrooms"],
},
{
title: "soup",
serves: 1,
ingredients: ["water", "flour", "peas", "mushroom"],
},
];
for (let i = 0; i < recipes.length; i++) {
console.log(recipes[i].title);
console.log("Serves: ", recipes[i].serves);
console.log("Ingredients:");
for (let j = 0; j < recipes[i].ingredients.length; j++) {
console.log(recipes[i].ingredients[j]);
}
console.log(" ");
}
11 changes: 10 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,15 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
let currencyObject = {};

for (let aCountryCurrency of countryCurrencyCodes) {
const singleCountry = aCountryCurrency[0];
const singleCurrency = aCountryCurrency[1];
currencyObject[singleCountry] = singleCurrency;
}

return currencyObject;
}

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

function createShoppingList(recipe) {
// write code here
let shoppingList = {};
let theRecipeName = recipe.name;
let shoppingIngredients = [];

for (let ingredient of recipe.ingredients) {
let fridgeArray = pantry.fridgeContents;
let cupboardArray = pantry.cupboardContents;
if (
fridgeArray.includes(ingredient) ||
cupboardArray.includes(ingredient)
) {
} else {
shoppingIngredients.push(ingredient);
}
}
shoppingList["name"] = theRecipeName;
shoppingList["items"] = shoppingIngredients;
return shoppingList;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
20 changes: 17 additions & 3 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@ const MENU = {
falafel: 7.25,
};

let cashRegister = {
// write code here
}


let cashRegister = {
orderBurger: function (balance) {
if (balance >= MENU.burger) {
return balance - MENU.burger;
} else {
return balance;
}
},
orderFalafel: function (balance) {
if (balance >= MENU.falafel) {
return balance - MENU.falafel;
} else {
return balance;
}
},
};
/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
32 changes: 22 additions & 10 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,53 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83)).toEqual("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("a score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toEqual("B");
});
/*
Write a test that checks a score of 68 is grade C
*/

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

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

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

test("a score of 55 is grade D", () => {
expect(convertScoreToGrade(55)).toEqual("D");
});

/*
Write a test that checks a score of 49 is grade E
*/

test("a score of 49 is grade E", () => {
expect(convertScoreToGrade(49)).toEqual("E");
});

/*
Write a test that checks a score of 30 is grade E
*/

test("a score of 30 is grade E", () => {
expect(convertScoreToGrade(30)).toEqual("E");
});

/*
Write a test that checks a score of 70 is grade B
*/

test("a score of 70 is grade B", () => {
expect(convertScoreToGrade(70)).toEqual("B");
});
Loading