Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Closed
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
Binary file added .DS_Store
Binary file not shown.
45 changes: 45 additions & 0 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ Exercise 1:
"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/

let intro = writers.forEach ((info)=> {
console.log (
"Hi, my name is " +
info.firstName + " " + info.lastName +
". I am " +
info.age +
" years old, and work as a " +
info.occupation + "."
)
}

);
/*
Exercise 2:

Expand All @@ -69,10 +81,43 @@ Exercise 2:
"Writer {firstName} {lastName} died at {age} years old."
*/

// let overFortyAndBelowFortyNine = writers
// .filter((element) => element.age > 40 && element.age < 49)
// .map((element) => console.log(element.age));


let between40and49 = writers.filter((info) => {
return info.age >= 40 && info.age <= 49;
}).map(between40and49 => {
console.log (
"Hi, my name is " +
between40and49.firstName + " " + between40and49.lastName +
". I am " +
between40and49.age +
" years old, and work as a " +
between40and49.occupation + "."
)
});


/*
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."
*/

let alive = writers.filter((info) => {
info.alive = true &&
info.age >= 40 &&
info.age <= 49
}).map(alive => {
console.log(
"Hi, my name is " +
alive.firstName + " " + alive.lastName +
". I am " +
alive.age +
" years old."
)})

36 changes: 31 additions & 5 deletions mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,45 @@ You have to implement the missing features according to the specification.
let bottle = {
volume: 0,
fillUp: function () {
// calling this function should pour your bottle full (volume = 100);
if (this.volume === 100) {
return;
} else {
const volumeToFillUp = 100 - this.volume;
this.volume += volumeToFillUp;
}
// calling this funcition should completely fill your bottle (volume = 100);
},
pour: function () {
// calling this function should increase your bottle volume by 10 unit;
if (this.volume === 100) {
return;
} else {
this.volume += 10;
}
// calling this function should increase your bottle volume by 10 units;
},
drink: function () {
// calling this function should decrease your bottle volume by 10 unit;
if (this.volume === 0) {
return;
} else {
this.volume -= 10;
}
// calling this function should decrease your bottle volume by 10 units;
},
isFull: function () {
// this function should return true if your bottle is empty;
if (this.volume === 100) {
return true;
} else {
return false;
}
// this function should return true if your bottle is full;
},
isEmpty: function () {
// this function should return true if your bottle is full;
if (this.volume === 0) {
return true;
} else {
return false;
}
// this function should return true if your bottle is empty;
},
};

Expand Down
42 changes: 37 additions & 5 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", "Bananas", "Black tea"],
thursday: ["Lamb", "Salt", "Bulgur", "Potato"],
friday: ["Rice milk", "Blueberries", "Porridge", "Banana", "Cinnamon"],
saturday: ["Olive oil", "Potato", "Salmon", "Asparagus"],
Expand All @@ -24,19 +24,22 @@ let weeklyMealPlan = {

/*
Exercise 1:
Loop through the weekly meal plan object to gather weakly ingredients into the weeklyGroceriesToBuy array.
Loop through the weekly meal plan object to gather weekly ingredients into the weeklyGroceriesToBuy array.
Then use console.log() to print out the list.
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];
let weeklyGroceriesToBuy = [Object.values(weeklyMealPlan)];
console.log(weeklyGroceriesToBuy);

/*
Exercise 2:
Loop through your list again, but now only collect the weekend items into the weeklyGroceriesToBuy array.
Then use console.log() to print out the list.
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];
let weekendGroceriesToBuy = Object.values(weeklyMealPlan["saturday"]);
console.log(weekendGroceriesToBuy.length)


/*
Exercise 3:
Expand All @@ -46,7 +49,7 @@ Exercise 3:
Finally use console.log() to print out the Object.
*/
// Gather weekend item names into this object
let numberOfItemsPerWeak = {
let numberOfItemsPerWeek = {
monday: 0,
tuesday: 0,
wednesday: 0,
Expand All @@ -55,3 +58,32 @@ let numberOfItemsPerWeak = {
saturday: 0,
sunday: 0,
};


// for (const key in numberOfItemsPerWeek) {
// let weekendGroceriesToBuy = (Object.values(weeklyMealPlan[`${key}`])).length;
// if (Object.hasOwnProperty.call(numberOfItemsPerWeek, key)) {
// const newElement = (numberOfItemsPerWeek[key] + weekendGroceriesToBuy);
// let element = {
// [key]:newElement
// }
// console.log(element)
// }

// }

for (ingredients in weeklyMealPlan) {
numberOfItemsPerWeek[ingredients] = weeklyMealPlan[ingredients].length;
}

console.log(numberOfItemsPerWeek);


// for (const key in numberOfItemsPerWeek) {
// let weekendGroceriesToBuy = (Object.values(weeklyMealPlan[`${key}`])).length;
// if (Object.hasOwnProperty.call(numberOfItemsPerWeek, key)) {
// const element = {[key]:(numberOfItemsPerWeek[key] + weekendGroceriesToBuy)};
// console.log(element)
// }

// }
33 changes: 27 additions & 6 deletions mandatory/4-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ let people = [
company: "POWERNET",
name: {
first: "Clay",
last: "Livingston",
last: "Livingstone",
},
email: "clay.livingston@powernet.com",
friends: [
Expand Down Expand Up @@ -386,7 +386,9 @@ First, I want you to find all of my friends who are 35 or older.

*/

let thirtyFiveOrOlder = [];
let thirtyFiveOrOlder = people.filter((info) => {
return info.age >= 35;}
);

/*
3) Find the email address
Expand All @@ -395,8 +397,12 @@ Next, I want you to find all of the people who work for "POWERNET" and then stor

*/

let powerNetEmails = [];
let powerNetEmails = people.filter((info) =>
info.company.includes("POWERNET"))
.map((elem)=> elem.email)
.sort() ;

console.log(powerNetEmails);
/*

3) Friends with "Stacie Villarreal"
Expand All @@ -409,7 +415,12 @@ This time, I only want the full names of the people are who friends with her.

*/

let friendsWithStacie = [];
let friendsWithStacie = people.filter((info) =>
info.friends.some(info => info.name.includes("Stacie Villarreal")))
.map((elem)=> `${elem.name.first} ${elem.name.last}`)
.reverse();

console.log(friendsWithStacie);

/*

Expand All @@ -423,7 +434,16 @@ This time, I only want the full names of the people who can multitask

*/

let friendsWhoCanMultitask = [];
let friendsWhoCanMultitask = people.flatMap((info) =>
// info.friends.some(info =>
info.friends.filter(hello => hello.skills.includes("Multi-tasking")))
.map((elem)=> `${elem.name}`)
.reverse();

console.log(friendsWhoCanMultitask);


// console.log(people.flatMap((info) => info)

/*
==================================================
Expand Down Expand Up @@ -460,9 +480,10 @@ test("Powernet email addresses", powerNetEmails, [
]);

test("Friends who can multitask", friendsWhoCanMultitask, [
"Rush May",

"Luz Newton",
"Castro Castaneda",
"Cunningham Shelton",
"Gena Good",
"Rush May",
]);
41 changes: 39 additions & 2 deletions mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ The Recipe Card
Never forget another recipe!

Create an object to hold information on your favorite recipe.

It should have properties for

- Title (a string),
Expand All @@ -24,4 +23,42 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
title: "Hot Chocolate",
serves: 1,
ingredients: ['cocoa', 'milk']
},

{
title: "Beans On Toast",
serves: 1,
ingredients:['beans', 'toast']
},
{
title: "Cheese On Toast",
serves: 3,
ingredients: ['cheese', 'toast']
},
{

title: "apples",
serves: 3,
ingredients: ['apple', 'cinnamon']
},
{

title: "cake",
serves: 8,
ingredients: ['flour', 'sugar', 'butter']
}

];

for (i of recipes) {
console.log(i.title);
console.log(`Serves: ${i.serves}`);
console.log("Ingredients:");
for (j of i.ingredients) {
console.log(j);
}}
45 changes: 43 additions & 2 deletions mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,49 @@ Exercise 2
=====
Now use an if/else statement to change the output depending on whether you read it yet or not.

If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolkien', and if not, log a string like 'You still need to read "The Lord of the Rings" by J.R.R. Tolkien.'
If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolkien', and
if not, log a string like 'You still need to read "The Lord of the Rings" by J.R.R. Tolkien.'

**/

let books = [];
let books = [
{
book: "Cat in the hat",
author: "Dr Seuss",
read: true
},
{
book: "Harry Potter",
author: "J K Rowling's",
read: true
},
{
book: "The lion the witch and wardrobe",
author: "C S Lewis",
read: true
},
{
book: "The Alchemist",
author: "Paulo Cohio",
read: false
},
{
book: "Percy Jackson and the lightning thief",
author: "Rick Riordan",
read: false
}
];
//exercise 1
for (i of books) {
console.log(i.book);
console.log(i.author);
}

//exercise 2

for (i of books) {
if (i.read === true) {
console.log(`You have read ${i.book} by ${i.author}`);
} else {
console.log(`You still need to read ${i.book} by ${i.author}`);
}}