Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.ignoreWords": [
"azkaban"
]
}
20 changes: 18 additions & 2 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ Exercise 1:

"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/

for (let obj of writers){
// console.log(obj);
console.log(`Hi, my name is ${obj.firstName} ${obj.lastName}. I am ${obj.age} years old, and work as a ${obj.occupation}`);
};
/*
Exercise 2:

Expand All @@ -68,11 +71,24 @@ Exercise 2:

"Writer {firstName} {lastName} died at {age} years old."
*/

for (let el of writers){
// console.log(el);
let match = (el.age >= 40 && el.age <= 49 && el.alive === false);
if (match === true){
console.log(`Writer ${el.firstName} ${el.lastName} died at ${el.age} years old.`);
}
}
/*
Exercise 3:

Only `console.log()` out alive writers who are in their 40s (meaning between 40 and 49):

"Hi, my name is {firstName} {lastName}. I am {age} years old."
*/
for (let item of writers){
// console.log(item);
let match2 = (item.age >= 40 && item.age <= 49 && item.alive === true);
if(match2 === true){
console.log(`Hi, my name is ${item.firstName} ${item.lastName}. I am ${item.age} years old.`);
}
}
30 changes: 22 additions & 8 deletions mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Create an object that acts a water bottle.
Create an object that acts like a water bottle.

It will need a volume property to store how full or empty the bottle is.

Expand All @@ -23,19 +23,33 @@ You have to implement the missing features according to the specification.
let bottle = {
volume: 0,
fillUp: function () {
// calling this function should completely fill your bottle (volume = 100);
this.volume = 100;// calling this function should completely fill your bottle (volume = 100);
},
pour: function () {
// calling this function should increase your bottle volume by 10 units;
if (this.volume <100){
this.volume = this.volume + 10;
} else if(this.volume === 100){
return "Bottle full";
}// calling this function should increase your bottle volume by 10 units;
},
drink: function () {
// calling this function should decrease your bottle volume by 10 units;
if(this.volume >=10){
this.volume = this.volume - 10;
}else if(this.volume === 0){
return "Sorry! Bottle is empty, please re-fill";
} // calling this function should, decrease your bottle volume by 10 units;
},
isFull: function () {
// this function should return true if your bottle is full;
if (this.volume === 100){
return true;
}
return false;// this function should return true if your bottle is full;
},
isEmpty: function () {
// this function should return true if your bottle is empty;
if (this.volume === 0){
return true;
}
return false; // this function should return true if your bottle is empty;
},
};

Expand All @@ -51,7 +65,7 @@ Extra question:
Leave your answer below:
*/

// Write you answer to the question here
// Write you answer to the question here - I think it would become confusing to refer to the object by it's name within the object, it makes code more readable as well and since the object represents a local environment it is logical.

/*
Once you have completed your object run the following
Expand Down Expand Up @@ -159,7 +173,7 @@ if (bottle.isEmpty()) {
}

if (bottle.volume === 0) {
console.log(`That's correct! Empty bottle volume is repesented as zero.`);
console.log(`That's correct! Empty bottle volume is represented as zero.`);
} else {
failed = true;

Expand Down
36 changes: 34 additions & 2 deletions mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Complete the exercises below.
let weeklyMealPlan = {
monday: ["Cheese", "Eggs", "Tomato", "Paprika", "Leek"],
tuesday: ["Wrap", "Tuna", "Canned beans", "Cheese", "Carrot", "Aubergine"],
wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"],
wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"],
thursday: ["Lamb", "Salt", "Bulgur", "Potato"],
friday: ["Rice milk", "Blueberries", "Porridge", "Banana", "Cinnamon"],
saturday: ["Olive oil", "Potato", "Salmon", "Asparagus"],
Expand All @@ -28,16 +28,42 @@ Exercise 1:
The weeklyGroceriesToBuy array shouldn't contain any repeating items.
Then use console.log() to print out the list.
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];

let weeklyEntries = Object.entries(weeklyMealPlan);
// console.log(weeklyEntries);
for (let item of weeklyEntries){
// console.log(item[1]);
item[1].filter(el =>{
// console.log(el);
if (weeklyGroceriesToBuy.includes(el)){
return false ;
}else {
weeklyGroceriesToBuy.push(el);
}
return weeklyGroceriesToBuy;
});

}
// console.log(weeklyGroceriesToBuy); // Gather all week item names into this array

/*
Exercise 2:
Loop through your list again, but now only collect the weekend items into the weekendGroceriesToBuy array.
Then use console.log() to print out the list.
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];
weeklyEntries.filter(el =>{
// console.log(el);
if(el[0] === "saturday" || el[0] === "sunday"){
weekendGroceriesToBuy.push(el[1]);
}
return weekendGroceriesToBuy;
});

// console.log(weekendGroceriesToBuy);


/*
Exercise 3:
Expand All @@ -56,3 +82,9 @@ let numberOfItemsPerWeek = {
saturday: 0,
sunday: 0,
};
for (let day in weeklyMealPlan){
// console.log(weeklyMealPlan[day].length);
// console.log(numberOfItemsPerWeek[day]);
numberOfItemsPerWeek[day] = weeklyMealPlan[day].length;
}
console.log(numberOfItemsPerWeek);
33 changes: 33 additions & 0 deletions mandatory/4-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ First, I want you to find all of my friends who are 35 or older.
*/

let thirtyFiveOrOlder = [];
for (let person of people){
// console.log(person.age);
if(person.age >= 35){
thirtyFiveOrOlder.push(person);
}
}
// console.log(thirtyFiveOrOlder);


/*
3) Find the email address
Expand All @@ -396,6 +404,13 @@ Next, I want you to find all of the people who work for "POWERNET" and then stor
*/

let powerNetEmails = [];
for (let person of people){
if (person.company === "POWERNET"){
powerNetEmails.unshift(person.email);
}
}
// console.log(powerNetEmails);


/*

Expand All @@ -410,6 +425,15 @@ This time, I only want the full names of the people are who friends with her.
*/

let friendsWithStacie = [];
for (friend of people){
// console.log(friend);
for (item of friend.friends){
// console.log(item.name);
if (item.name === "Stacie Villarreal"){
friendsWithStacie.unshift(`${friend.name.first} ${friend.name.last}`);
}
}
}

/*

Expand All @@ -424,6 +448,15 @@ This time, I only want the full names of the people who can multitask
*/

let friendsWhoCanMultitask = [];
for (let object of people){
// console.log(object.friends);
for (let arr of object.friends)
// console.log(arr.skills);
if (arr.skills.includes("Multi-tasking")){
friendsWhoCanMultitask.push(arr.name);
}
}
// console.log(friendsWhoCanMultitask);

/*
==================================================
Expand Down
45 changes: 43 additions & 2 deletions mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The Recipe Card
Never forget another recipe!

Create an object to hold information on your favorite recipe.
Create an object to hold information on your favorite recipes.

It should have properties for

Expand All @@ -24,4 +24,45 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
Title: "Scrambled eggs",
Servings: 2,
Ingredients: ["eggs", "bread", "butter"]
},
{
Title: "Boeber",
Servings: 4,
Ingredients: ["Vermicelli", "Milk", "Cinnamon", "Sugar","Sago"]
},
{
Title: "Koesisters",
Servings: 6,
Ingredients: ["Cake Flour", "Milk", "Aniseed", "Sugar", "Baking powder","Water"]
},
{
Title: "Spaghetti bolognese",
Servings: 4,
Ingredients: ["Spaghetti", "Mince", "Tomato Paste", "Sugar", "Cinnamon Sticks","Black Pepper","Salt","Tomatoes","Basil","Bay leaves","Pimento"]
},
{
Title: "Chicken curry masala",
Servings: 4,
Ingredients: ["Skinless chicken breasts", "Onion", "Salt", "Curry powder","Bay leaves","Tumeric powder","Masala powder","Basmati rice","Tomato salad"]
},

];

let recipeCard = function (recipeArr){
for (let recipe of recipeArr){
console.log(recipe.Title);
console.log("Serves: ", recipe.Servings);
console.log("Ingredients: ");
recipe.Ingredients.forEach(element => {
console.log(element);
});
console.log(" ");
}
};

recipeCard(recipes);
53 changes: 52 additions & 1 deletion mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,55 @@ and if not, log a string like 'You still need to read "The Lord of the Rings" by

**/

let books = [];
let books = [
{
Title: "Harry Potter and the Philosopher's Stone",
Author: "J. K. Rowling",
Read: true,
},
{
Title: "Harry Potter and the Chamber of Secrets",
Author: "J. K. Rowling",
Read: true,
},
{
Title: "Harry Potter and the Prisoner of Azkaban",
Author: "J. K. Rowling",
Read: true,
},
{
Title: "Harry Potter and the Goblet of Fire",
Author: "J. K. Rowling",
Read: false,
},
{
Title: "Harry Potter and the Order of the Phoenix",
Author: "J. K. Rowling",
Read: false,
},
{
Title: "Harry Potter and the Half-blood Prince",
Author: "J. K. Rowling",
Read: false,
},
{
Title: "Harry Potter and the Deathly Hallows",
Author: "J. K. Rowling",
Read: false,
},
];

function bookList (bookArr){
for(let book of bookArr){
console.log(`${book.Title} by ${book.Author}`);
if (book.Read){
console.log(`You have read ${book.Title}`);
}else{
console.log(`You still need to read ${book.Title}`);
}
console.log(" ");
}
};

bookList(books);

15 changes: 14 additions & 1 deletion mandatory/7-budgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ Should give return the answer of 62600.

**/

function getBudgets(peopleArray) {}
function getBudgets(peopleArray) {
let budget = []
if(peopleArray.length === 0){
return 0;
}
else{
for(let person of peopleArray){
budget.push(person.budget);
}
}
return budget.reduce(function(accumulator,currentValue){
return accumulator + currentValue;
});
}

/*
==================================================
Expand Down
12 changes: 10 additions & 2 deletions mandatory/8-cheap-diner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Frugal Gentleman

Atticus has been invited to a dinner party, and he decides to purchase a meal to share with he party
Atticus has been invited to a dinner party, and he decides to purchase a meal to share with the party
Being a very frugal gentleman (yet disliking looking like a cheapskate), he decides to use a very simple rule.

In any selection of two or more meals, he will always buy the second-cheapest.
Expand Down Expand Up @@ -30,7 +30,15 @@ Should give the answer "Nothing :("
**/

function chooseMeal(mealArray) {
// Write your code here
if (mealArray.length === 0 ){
return "Nothing :(";
} else if(mealArray.length ===1){
return mealArray[0].name;
}else if( mealArray.length >=2){
mealArray.sort((highPrice, lowPrice)=> highPrice.price- lowPrice.price);
// console.log(mealArray);
return mealArray[1].name;
}
}

/*
Expand Down