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
17 changes: 16 additions & 1 deletion 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}."
*/

writers.forEach(function(writer){
console.log( `Hi my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and I work as a ${writer.occupation}.`);
});

/*
Exercise 2:

Expand All @@ -68,6 +71,12 @@ Exercise 2:

"Writer {firstName} {lastName} died at {age} years old."
*/
const writersIn40sAndDead = writers.filter(function(writer){
if(writers.age <= 40 && writers.age > 50 && writers.alive === 'false') {
}
return console.log(`Writer ${writer.firstName} ${writer.lastName} died at age ${writer.age}`);
});


/*
Exercise 3:
Expand All @@ -76,3 +85,9 @@ Exercise 3:

"Hi, my name is {firstName} {lastName}. I am {age} years old."
*/

const writersIn40sAndAlive = writers.filter(function(writer){
if(writers.age <= 40 && writers.age > 50 && writers.alive === 'true') {
}
return console.log(`Writer ${writer.firstName} ${writer.lastName} I am ${writer.age} years old`);
});
7 changes: 6 additions & 1 deletion mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@ You have to implement the missing features according to the specification.
// Here is your starting point:
let bottle = {
volume: 0,
fillUp: function () {
fillUp: function (fill) {
// calling this function should pour your bottle full (volume = 100);
return this.volume = this.volume + (100 - this.volume);
},
pour: function () {
// calling this function should increase your bottle volume by 10 unit;
return this.volume = this.volume <= 90 ? this.volume + 10 : this.volume;
},
drink: function () {
// calling this function should decrease your bottle volume by 10 unit;
return this.volume = this.volume >= 10 ? this.volume - 10 : this.volume;
},
isFull: function () {
// this function should return true if your bottle is empty;
return this.volume === 100 ? true : false;
},
isEmpty: function () {
// this function should return true if your bottle is full;
return this.volume === 0 ? true : false;
},
};

Expand Down
18 changes: 17 additions & 1 deletion mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Exercise 1:
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];
for (j in weeklyMealPlan) {
weeklyGroceriesToBuy = weeklyGroceriesToBuy.concat(weeklyMealPlan[j]);
}

console.log(weeklyGroceriesToBuy);


/*
Exercise 2:
Expand All @@ -37,7 +43,11 @@ Exercise 2:
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];

for (j in weeklyMealPlan)
if (j === 'saturday' || j === 'sunday') {
weekendGroceriesToBuy = weekendGroceriesToBuy.concat(weeklyMealPlan[j]);
}
console.log(weekendGroceriesToBuy);
/*
Exercise 3:
Loop through your weekly meal plan:
Expand All @@ -55,3 +65,9 @@ let numberOfItemsPerWeak = {
saturday: 0,
sunday: 0,
};

for (j in weeklyMealPlan) {
numberOfItemsPerWeak[j] = weeklyMealPlan[j].length;
}

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

*/

let thirtyFiveOrOlder = [];
//arrow function
let thirtyFiveOrOlder = people.filter(arr => arr.age >= 35);



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

*/

let powerNetEmails = [];
let powerNetEmails = people.filter(arr => arr.company === "POWERNET").map(arr => arr.email).reverse();

/*

3) Friends with "Stacie Villarreal"

Next, I want you to find all of my friends who are friends with Stacie Villarreal.

You can see who people's friends are by seeing the "friends" array in each of my friends objects.

This time, I only want the full names of the people are who friends with her.

*/


let friendsWithStacie = [];
for (let person of people) {
for (let friend of person.friends) {
if (friend.name === "Stacie Villarreal") {
friendsWithStacie.push(`${person.name.first} ${person.name.last}`);
}
}
}
friendsWithStacie.reverse().forEach(f => console.log(f));



/*

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

*/

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

/*
==================================================
Expand Down Expand Up @@ -455,7 +468,7 @@ test("Friends with Stacie Villarreal", friendsWithStacie, [
]);

test("Powernet email addresses", powerNetEmails, [
"clay.livingston@powernet.com",
"clay.livingstone@powernet.com",
"gloria.hall@powernet.com",
]);

Expand Down
41 changes: 40 additions & 1 deletion mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,43 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
title: 'Pizza',
serves: 2,
ingredients: ['pizza dough', 'Mozarella', 'Pizza sauce'],

},
{
title: 'Beans on toast',
serves: 1,
ingredients: ['Beans', 'Bread', 'Butter'],
},
{
title: 'Pasta Bake',
serves: 4,
ingredients: ['Pasta', 'Pasta sauce', 'Cheese'],
},

{
title: 'Bangers and mash',
serves: 2,
ingredients: ['Sausages', 'Potatoes', 'Gravy'],
},

{
title: 'Apple pie and custard',
serves: 2,
ingredients: ['Apples', 'Custard', 'Shortcrust pastry'],

}
];

for (i of recipes) {
console.log(i.title);
console.log(`Serves: ${i.serves}`);
console.log("Ingredients:");
for (j of i.ingredients) {
console.log(j);
}
}
43 changes: 42 additions & 1 deletion mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,45 @@ If you read it, log a string like 'You already read "The Hobbit" by J.R.R. Tolki

**/

let books = [];
let books = [
{
title: 'The Hobbit',
author: 'J.R.R. TOLKEIN',
read: false,
},
{
title: 'The Lord of the rings',
author: 'J.R.R. TOLKEIN',
read: false,
},
{
title: 'The Two Towers',
author: 'J.R.R. TOLKEIN',
read: true,
},
{
title: 'The King returns',
author: 'J.R.R. TOLKEIN',
read: false,
},
{
title: 'The Hobbit: Battle of 5 armys',
author: 'J.R.R. TOLKEIN',
read: true,
},
];

for (i of books) {
console.log(`${i.title} by ${i.author}`);
}


// exercise 2

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