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
6 changes: 5 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,11 @@ let basketballTeam = {
*/

// write code here

let newArray = basketballTeam.topPlayers.sort()
console.log(newArray);
for (num of newArray ) {
console.log(num)
}

/* EXPECTED RESULT

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

Expand Down
9 changes: 5 additions & 4 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ let student = {
examScore: 65,
hasPassed: false
};

/*
Using bracket notation
- Add a property to the student object for attendance
- Set the value of attendance to 90
*/

// write code here

// let attendance = student.attendance;
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 @@ -26,7 +25,9 @@ let student = {
*/

// write code here

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

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

console.log(car["colour"]);
console.log(car["colour"]); // we have not assigned a new property named colour

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`); // there is not a property called firstName
}

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

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
getName: function () {
"My pet's name is Fluffy"; // if we would add return then the function would return the text "My pet's name is Fluffy" otherwise its undefined
},
};

Expand Down
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

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

// write code here
// write code here
let recipeCard = {
recipe1: {
name: "Salad",
serves: 3,
ingredients: ["cucumber", "tomatoes", "beans"],
},
recipe2: {
name: "Pie",
serves: 2,
ingredients: ["cheese", "flour", "water", "butter"],
},
recipe3: {
name: "Pizza",
serves: 3,
ingredients: ["olives", "flour", "oil", "peperoni"],
},
recipe4: {
name: "Fries",
serves: 3,
ingredients: ["potatoes", "oil", "salt", "pepper"],
},
recipe5: {
name: "Rice",
serves: 4,
ingredients: ["rice", "carrots", "peas"],
},
};
console.log(recipeCard.recipe1.name);
console.log(`Serves:${recipeCard.recipe1.serves}`);
for (index in recipeCard.recipe1.ingredients) {
console.log(recipeCard.recipe1.ingredients[index]);
}
console.log(recipeCard.recipe2.name);
console.log(`Serves:${recipeCard.recipe2.serves}`);
for (index in recipeCard.recipe2.ingredients) {
console.log(recipeCard.recipe2.ingredients[index]);
}
console.log(recipeCard.recipe3.name);
console.log(`Serves:${recipeCard.recipe1.serves}`);
for (index in recipeCard.recipe3.ingredients) {
console.log(recipeCard.recipe3.ingredients[index]);
}
console.log(recipeCard.recipe4.name);
console.log(`Serves:${recipeCard.recipe4.serves}`);
for (index in recipeCard.recipe4.ingredients) {
console.log(recipeCard.recipe4.ingredients[index]);
}
console.log(recipeCard.recipe5.name);
console.log(`Serves:${recipeCard.recipe5.serves}`);
for (index in recipeCard.recipe5.ingredients) {
console.log(recipeCard.recipe5.ingredients[index]);
}
5 changes: 5 additions & 0 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const COUNTRY_CURRENCY_CODES = [

function createLookup(countryCurrencyCodes) {
// write code here
let createLookup = {};
createLookup.forEach(element => createLookup[element[0]]= [element[1]];

// return Object.keys(COUNTRY_CURRENCY_CODES)
}
return createLookup;

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
Expand Down
31 changes: 27 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@ let pantry = {

function createShoppingList(recipe) {
// write code here
}
let recipeName = recipe.name;
let recipeIngredients = recipe.ingredients;

let emptyContainer = [];

recipeIngredients.forEach((item) => {
if (
!pantry.fridgeContents.includes(item) &&
!pantry.cupboardContents.includes(item)
) {
emptyContainer.push(item);
}
});
return {
name: recipeName,
items: emptyContainer,
};
}
/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand All @@ -43,11 +59,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"],
});
});
});
16 changes: 14 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ 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;
}
};


/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"homepage": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1-London8#readme",
"devDependencies": {
"jest": "^26.6.3"
},
"dependencies": {
"jshint": "^2.13.5"
}
}