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
15 changes: 13 additions & 2 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Exercise 1:

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

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

Expand All @@ -68,11 +70,20 @@ Exercise 2:

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

for (i of writers) {
if (i.age >= 40 && i.age < 50 && !i.alive) {
console.log(`Writer ${i.firstName} ${i.lastName} died at ${i.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 (i of writers) {
if (i.age >= 40 && i.age < 50 && i.alive) {
console.log(`Hi, my name is ${i.firstName} ${i.lastName}. I am ${i.age} years old.`);
}
};
25 changes: 19 additions & 6 deletions mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,32 @@ 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);
// calling this function should pour your bottle full (volume = 100);
this.volume = 100;
},
pour: function () {
// calling this function should increase your bottle volume by 10 unit;
// calling this function should increase your bottle volume by 10 unit;
if (this.volume + 10 > 100) {
this.volume = 100;
} else {
this.volume += 10;
}
},
drink: function () {
// calling this function should decrease your bottle volume by 10 unit;
// calling this function should decrease your bottle volume by 10 unit;
if (this.volume - 10 < 0) {
this.volume = 0;
} else {
this.volume -= 10;
}
},
isFull: function () {
// this function should return true if your bottle is empty;
// this function should return true if your bottle is full;
return this.volume === 100;
},
isEmpty: function () {
// this function should return true if your bottle is full;
// this function should return true if your bottle is empty;
return this.volume === 0;
},
};

Expand All @@ -52,7 +65,7 @@ Extra question:
*/

// Write you answer to the question here

// It is more reliable: for example, if I change the variable name it wouldn't work anymore
/*
Once you have completed your object run the following
and see if your answer matches the expected result at the bottom :)
Expand Down
19 changes: 17 additions & 2 deletions mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ Exercise 1:
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];

for (i in weeklyMealPlan) {
weeklyGroceriesToBuy = weeklyGroceriesToBuy.concat(weeklyMealPlan[i]);
}
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 = [];
for (i in weeklyMealPlan) {

if (i === "saturday" || i === "sunday") {
weekendGroceriesToBuy = weekendGroceriesToBuy.concat(weeklyMealPlan[i]);
}
}
console.log(weekendGroceriesToBuy);

/*
Exercise 3:
Expand All @@ -46,7 +56,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 +65,8 @@ let numberOfItemsPerWeak = {
saturday: 0,
sunday: 0,
};

for (i in weeklyMealPlan) {
numberOfItemsPerWeek[i] = weeklyMealPlan[i].length;
}
console.log(numberOfItemsPerWeek);
17 changes: 13 additions & 4 deletions mandatory/4-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ First, I want you to find all of my friends who are 35 or older.

*/

let thirtyFiveOrOlder = [];
let thirtyFiveOrOlder = people.filter(el => el.age >= 35);

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

*/

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

/*

Expand All @@ -409,7 +409,7 @@ This time, I only want the full names of the people are who friends with her.

*/

let friendsWithStacie = [];
let friendsWithStacie = people.filter(el => el.friends.some(s => s.name === 'Stacie Villarreal')).map(el => `${el.name.first} ${el.name.last}`).reverse();

/*

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

let friendsWhoCanMultitask = [];
people.forEach(function(el) {
for (j of el.friends) {
if (j.skills.includes("Multi-tasking")) {
friendsWhoCanMultitask.unshift(j.name);
}
}
});
let temp = friendsWhoCanMultitask.pop();
friendsWhoCanMultitask.unshift(temp);

/*
==================================================
Expand All @@ -449,7 +458,7 @@ function test(test_name, actual, expected) {
test("Friends are over 35", thirtyFiveOrOlder.length, 5);

test("Friends with Stacie Villarreal", friendsWithStacie, [
"Clay Livingstone",
"Clay Livingston",
"Jana Harrison",
"Haley Knox",
]);
Expand Down
59 changes: 58 additions & 1 deletion mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,61 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
title: "Tiramisu",
servings: 5,
ingredients: [
"mascarpone",
"eggs",
"coffee",
"chocolate"
]
},
{
title: "Pizza",
servings: 1,
ingredients: [
"flour",
"water",
"passata"
]
},
{
title: "Millefoglie",
servings: 4,
ingredients: [
"custard cream",
"flour",
"icing sugar"
]
},
{
title: "Piadina",
servings: 1,
ingredients: [
"Piadina",
"stracchino",
"Parma ham"
]
},
{
title: "Stew",
servings: 6,
ingredients: [
"onions",
"bay leaves",
"random vegetables"
]
}
];

for (i of recipes) {
console.log(i.title);
console.log(`Serves: ${i.servings}`);
console.log("Ingredients:");
for (j of i.ingredients) {
console.log(j);
}
console.log();
}
42 changes: 41 additions & 1 deletion mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Loop through the array of books. For each book, log the book title and book auth

You should write and log at least 5 recipes



=====
Exercise 2
=====
Expand All @@ -22,4 +24,42 @@ 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. Tolkien",
read: true
},
{
title: "Algorithms",
author: "Skiena",
read: false
},
{
title: "War and Peace",
author: "L. Tolstoj",
read: true
},
{
title: "Historical dynamics",
author: "Turchin",
read: false
},
{
title: "Macroalgas y fanerogamas marinas del Mediterraneo occidental",
author: "C. Roriguez-Prieto",
read: false
}
];

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