From 78d912b0bd363fdefdd2cbc4e5263109defd9700 Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:26:29 +0000 Subject: [PATCH 1/4] started part 1 - need to ammend a few sections --- mandatory/1-writers.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/mandatory/1-writers.js b/mandatory/1-writers.js index 55dc10b9..8c884081 100644 --- a/mandatory/1-writers.js +++ b/mandatory/1-writers.js @@ -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: @@ -69,6 +81,16 @@ 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 = info.filter((writers) => { + return writers.age >= 40 && writers.age <= 49; +}).map(getAge); + + /* Exercise 3: @@ -76,3 +98,16 @@ Exercise 3: "Hi, my name is {firstName} {lastName}. I am {age} years old." */ + +let alive = author.filter((info) => { + info.alive = true && + info.age >= 40 && + info.age <= 49 +}).map() + console.log( + "Hi, my name is " + + info.firstName + " " + info.lastName + + ". I am " + + info.age + + " years old." + ); \ No newline at end of file From d6c92a2ddf1b5677c74c59f12bc7dd65d5c6af59 Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Thu, 14 Jan 2021 19:52:10 +0000 Subject: [PATCH 2/4] mostly done --- mandatory/1-writers.js | 28 ++++++++++++++-------- mandatory/2-water-bottle.js | 36 +++++++++++++++++++++++++---- mandatory/3-groceries.js | 7 +++--- mandatory/4-people-I-know.js | 33 +++++++++++++++++++++----- mandatory/5-recipes.js | 41 ++++++++++++++++++++++++++++++-- mandatory/6-reading-list.js | 45 ++++++++++++++++++++++++++++++++++-- 6 files changed, 163 insertions(+), 27 deletions(-) diff --git a/mandatory/1-writers.js b/mandatory/1-writers.js index 8c884081..6e03a02f 100644 --- a/mandatory/1-writers.js +++ b/mandatory/1-writers.js @@ -86,9 +86,18 @@ Exercise 2: // .map((element) => console.log(element.age)); -let between40and49 = info.filter((writers) => { - return writers.age >= 40 && writers.age <= 49; -}).map(getAge); +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 + "." + ) +}); /* @@ -99,15 +108,16 @@ Exercise 3: "Hi, my name is {firstName} {lastName}. I am {age} years old." */ -let alive = author.filter((info) => { +let alive = writers.filter((info) => { info.alive = true && info.age >= 40 && info.age <= 49 -}).map() - console.log( +}).map(alive => { + console.log( "Hi, my name is " + - info.firstName + " " + info.lastName + + alive.firstName + " " + alive.lastName + ". I am " + - info.age + + alive.age + " years old." - ); \ No newline at end of file + )}) + \ No newline at end of file diff --git a/mandatory/2-water-bottle.js b/mandatory/2-water-bottle.js index 1c54abb3..dd999cb6 100644 --- a/mandatory/2-water-bottle.js +++ b/mandatory/2-water-bottle.js @@ -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; }, }; diff --git a/mandatory/3-groceries.js b/mandatory/3-groceries.js index 02486088..26d475ec 100644 --- a/mandatory/3-groceries.js +++ b/mandatory/3-groceries.js @@ -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"], @@ -24,11 +24,12 @@ 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: diff --git a/mandatory/4-people-I-know.js b/mandatory/4-people-I-know.js index ca7618f1..9abfc5aa 100644 --- a/mandatory/4-people-I-know.js +++ b/mandatory/4-people-I-know.js @@ -344,7 +344,7 @@ let people = [ company: "POWERNET", name: { first: "Clay", - last: "Livingston", + last: "Livingstone", }, email: "clay.livingston@powernet.com", friends: [ @@ -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 @@ -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" @@ -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); /* @@ -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) /* ================================================== @@ -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", ]); diff --git a/mandatory/5-recipes.js b/mandatory/5-recipes.js index 4c07f439..7eee9729 100644 --- a/mandatory/5-recipes.js +++ b/mandatory/5-recipes.js @@ -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), @@ -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); + }} \ No newline at end of file diff --git a/mandatory/6-reading-list.js b/mandatory/6-reading-list.js index 5dde8db9..707edb3b 100644 --- a/mandatory/6-reading-list.js +++ b/mandatory/6-reading-list.js @@ -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}`); + }} \ No newline at end of file From dbda5dd466e80118a148e2152bc6b7d2053e2d7b Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Thu, 14 Jan 2021 21:31:32 +0000 Subject: [PATCH 3/4] finished --- mandatory/3-groceries.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/mandatory/3-groceries.js b/mandatory/3-groceries.js index 26d475ec..a52a3cc8 100644 --- a/mandatory/3-groceries.js +++ b/mandatory/3-groceries.js @@ -37,7 +37,9 @@ Exercise 2: 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: @@ -47,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, @@ -56,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) +// } + +// } \ No newline at end of file From 69f4aeed1480bc39ce51ce5f07ad6b799e2caddc Mon Sep 17 00:00:00 2001 From: moniqueking57 <65675759+moniqueking57@users.noreply.github.com> Date: Sun, 24 Jan 2021 22:11:27 +0000 Subject: [PATCH 4/4] Create .DS_Store --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..de012ba66ca266654a5767f918a8bd8dd513630a GIT binary patch literal 6148 zcmeHK%Wl&^6upy%)(%2g2&vs5dBZNLl9pCtf#jM*5D92i2f6^%+Bj-0xt=OCU;nGv_*UJn?vli1~xKLF5pT1s7Pd(JV00FMQ5Q zIM>=?Zh=7eF;C}0%0VG8J%fOY$Z&D%`ZC}0%0UIFobaNzOdop0KhWR z(h!T!MZs}3dKwFb=z%ds1u81jM+~Ou$h&%+r?F6|=*0BlgXudneL`XK?x^p|;lwN| jkXtdvimiAJE)98C1VB$?p%59E`4EsYn8qmZR~7gL!w-t8 literal 0 HcmV?d00001