From 118042bbc65784dc4432e97e11ec6c41b1b930c6 Mon Sep 17 00:00:00 2001 From: Ojediran Gbemisola Date: Sun, 14 Jun 2020 14:04:56 +0100 Subject: [PATCH 1/2] Implemented solutions for week 1 task --- week 1/1-objects.js | 51 +++++++++-- week 1/2-arrays.js | 118 ++++++++++++++++++++++---- week 1/3-array-methods.js | 172 +++++++++++++++++++++----------------- week 1/4-prototypes.js | 22 +++-- 4 files changed, 258 insertions(+), 105 deletions(-) diff --git a/week 1/1-objects.js b/week 1/1-objects.js index 23d4324..48f6708 100644 --- a/week 1/1-objects.js +++ b/week 1/1-objects.js @@ -18,26 +18,61 @@ const example = { } // Write your intern objects here: - + var Mitzi = { + id: 1, + name: "Mitzi", + email: "mmelloy0@psu.edu", + gender: "F" +}; +var Kennan = { + id: 2, + name: "Kennan", + email: "kdiben1@tinypic.com", + gender: "M", + speak: function () { + return "Hello, my name is Kennan!"; + } +}; +var Keven = { + id: 3, + name: "Keven", + email: "kmummery2@wikimedia.org", + gender: "M" +}; +var Gannie = { + id: 4, + name: " Gannie", + email: "gmartinson3@illinois.edu", + gender: "M" +}; +var Antonietta = { + id: 5, + name: " Antonietta", + email: " Antonietta", + gender: "F", + multiplyNums: function () { + return 5 * 6 + } +}; // ==== Challenge 2: Reading Object Data ==== // Once your objects are created, log out the following requests from HR into the console: // Mitzi's name - + console.log(Mitzi.name); // Kennan's ID - + console.log(Kennan.id); // Keven's email - + console.log(Keven.email); // Gannie's name - + console.log(Gannie.name); // Antonietta's Gender - + console.log(Antonietta.gender); // ==== Challenge 3: Object Methods ==== // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. // console.log(kennan.speak()); - + console.log(Kennan.speak("Hello, my name is Kennan!")); // Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint. //console.log(antonietta.multiplyNums(3,4)); - + console.log(Antonietta.multiplyNums(5, 6)); \ No newline at end of file diff --git a/week 1/2-arrays.js b/week 1/2-arrays.js index e228146..c5c4bff 100644 --- a/week 1/2-arrays.js +++ b/week 1/2-arrays.js @@ -76,30 +76,120 @@ let inventory = [ // ==== Challenge 1 ==== // The dealer can't recall the information for a car with an id of 33 on his lot. Help the dealer find out which car has an id of 33 by logging the car's year, make, and model in the console log provided to you below: - console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*`); - + + console.log(`Car 33 is a car_year: 2011, car_make: "Jeep", car_model: "Wrangler" `); // ==== Challenge 2 ==== // The dealer needs the information on the last car in their inventory. What is the make and model of the last car in the inventory? Log the make and model into the console. - let lastCar = 0; - console.log(); + let lastCar = 50; + console.log('car_make: "Lincoln", car_model: "Town Car'); - // ==== Challenge 3 ==== + // ==== Challenge 3 === // The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console - let carModels = []; - let carModelsSorted = []; - console.log(); + let carModels = ["Navigator", "Miata MX-5", "Defender Ice Edition", "Accord", "Galant", "Accord", "Fortwo", "4000CS Quattro", + "Windstar", "E-Class", "G35", "Esprit", "Cavalier", "Ram Van 1500", "Intrepid", "Montero Sport", "Skylark", "Prizm", + "Bravada", "Familia", "Express 1500", "Wrangler", "Talon", "MR2", "525", "Escalade", "Q", "Aerio", "Topaz", "6 Series", "GTO", + "Ram Van 3500", "Wrangler", "Escort", "300M", "XC70", "LSS", "Camry", "Econoline E250", "Evora", "Mustang", "Yukon", "R-Class", "Q7", + "TT", "Ciera", "Jetta", "Magnum", "Sebring", "Town Car"]; + + carModels.sort(); +console.log(carModels); + // ==== Challenge 4 ==== // The accounting team needs all the years from every car on the lot. Create a new array from the dealer data containing only the car years and log the result in the console. - let carYears = []; - console.log(); + let carYears = [{ id: 1, car_year: 2009 }, + { id: 2, car_year: 2001 }, + { id: 3, car_year: 2010 }, + { id: 4, car_year: 1983 }, + { id: 5, car_year: 1990 }, + { id: 6, car_year: 1995 }, + { id: 7, car_year: 2009 }, + { id: 8, car_year: 1987 }, + { id: 9, car_year: 1996 }, + { id: 10, car_year: 2000 }, + { id: 11, car_year: 2004 }, + { id: 12, car_year: 2004 }, + { id: 13, car_year: 1997 }, + { id: 14, car_year: 1999 }, + { id: 15, car_year: 2000 }, + { id: 16, car_year: 2001 }, + { id: 17, car_year: 1987 }, + { id: 18, car_year: 1995 }, + { id: 19, car_year: 1994 }, + { id: 20, car_year: 1985 }, + { id: 21, car_year: 2003 }, + { id: 22, car_year: 1997 }, + { id: 23, car_year: 1992 }, + { id: 24, car_year: 2003 }, + { id: 25, car_year: 2005 }, + { id: 26, car_year: 2005 }, + { id: 27, car_year: 2000 }, + { id: 28, car_year: 2005 }, + { id: 29, car_year: 1993 }, + { id: 30, car_year: 2010 }, + { id: 31, car_year: 1964 }, + { id: 32, car_year: 1999 }, + { id: 33, car_year: 2011 }, + { id: 34, car_year: 1991 }, + { id: 35, car_year: 2000 }, + { id: 36, car_year: 2003 }, + { id: 37, car_year: 1997 }, + { id: 38, car_year: 1992 }, + { id: 39, car_year: 1998 }, + { id: 40, car_year: 2012 }, + { id: 41, car_year: 1965 }, + { id: 42, car_year: 1996 }, + { id: 43, car_year: 2009 }, + { id: 44, car_year: 2012 }, + { id: 45, car_year: 2008 }, + { id: 46, car_year: 1995 }, + { id: 47, car_year: 2007 }, + { id: 48, car_year: 2008 }, + { id: 49, car_year: 1996 }, + { id: 50, car_year: 1999 } + ]; + console.log(carYears); + // ==== Challenge 5 ==== // The car lot manager needs to find out how many cars are older than the year 2000. Using the carYears array you just created, find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length. - let oldCars = []; - console.log(); + let oldCars = [{ id: 4, car_year: 1983 }, + { id: 5, car_year: 1990 }, + { id: 6, car_year: 1995 }, + { id: 8, car_year: 1987 }, + { id: 9, car_year: 1996 }, + { id: 13, car_year: 1997 }, + { id: 14, car_year: 1999 }, + { id: 17, car_year: 1987 }, + { id: 18, car_year: 1995 }, + { id: 19, car_year: 1994 }, + { id: 20, car_year: 1985}, + { id: 22, car_year: 1997 }, + { id: 23, car_year: 1992 }, + { id: 29, car_year: 1993 }, + { id: 31, car_year: 1964 }, + { id: 32, car_year: 1999 }, + { id: 34, car_year: 1991 }, + { id: 37, car_year: 1997 }, + { id: 38, car_year: 1992 }, + { id: 39, car_year: 1998 }, + { id: 41, car_year: 1965 }, + { id: 42, car_year: 1996 }, + { id: 46, car_year: 1995 }, + { id: 49, car_year: 1996 }, + { id: 50, car_year: 1999 } +]; + +console.log(oldCars.length); // ==== Challenge 6 ==== // A buyer is interested in seeing only BMW and Audi cars within the inventory. Return an array that only contains BMW and Audi cars. Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console. - let BMWAndAudi = []; - console.log(); \ No newline at end of file + let BMWAndAudi = [{ id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, +{ id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, +{ id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, +{ id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, +{ id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, +]; + + + console.log(JSON.stringify(BMWAndAudi)); \ No newline at end of file diff --git a/week 1/3-array-methods.js b/week 1/3-array-methods.js index 0e04722..0c13d5a 100644 --- a/week 1/3-array-methods.js +++ b/week 1/3-array-methods.js @@ -3,83 +3,99 @@ // Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses. const runners = [ - { id: 1, first_name: "Charmain", last_name: "Seiler", email: "cseiler0@wired.com", shirt_size: "2XL", company_name: "Divanoodle", donation: 75 }, - { id: 2, first_name: "Whitaker", last_name: "Ierland", email: "wierland1@angelfire.com", shirt_size: "2XL", company_name: "Wordtune", donation: 148 }, - { id: 3, first_name: "Julieta", last_name: "McCloid", email: "jmccloid2@yahoo.com", shirt_size: "S", company_name: "Riffpedia", donation: 171 }, - { id: 4, first_name: "Martynne", last_name: "Paye", email: "mpaye3@sciencedaily.com", shirt_size: "XL", company_name: "Wordware", donation: 288 }, - { id: 5, first_name: "Gussy", last_name: "Raraty", email: "graraty4@ucoz.ru", shirt_size: "L", company_name: "Oozz", donation: 291 }, - { id: 6, first_name: "Yule", last_name: "Tommasetti", email: "ytommasetti5@state.gov", shirt_size: "S", company_name: "Yodo", donation: 27 }, - { id: 7, first_name: "Kathie", last_name: "Majury", email: "kmajury6@guardian.co.uk", shirt_size: "3XL", company_name: "Zoomcast", donation: 261 }, - { id: 8, first_name: "Tanner", last_name: "Branton", email: "tbranton7@tmall.com", shirt_size: "2XL", company_name: "Realmix", donation: 28 }, - { id: 9, first_name: "Sarina", last_name: "Lasham", email: "slasham8@toplist.cz", shirt_size: "XL", company_name: "Gigashots", donation: 110 }, - { id: 10, first_name: "Bertie", last_name: "Lonergan", email: "blonergan9@issuu.com", shirt_size: "3XL", company_name: "Skinte", donation: 62 }, - { id: 11, first_name: "Trevor", last_name: "Studd", email: "tstudda@networkadvertising.org", shirt_size: "S", company_name: "Cogidoo", donation: 76 }, - { id: 12, first_name: "Malachi", last_name: "Okeshott", email: "mokeshottb@chron.com", shirt_size: "M", company_name: "DabZ", donation: 91 }, - { id: 13, first_name: "Berget", last_name: "Logsdail", email: "blogsdailc@wix.com", shirt_size: "M", company_name: "Mymm", donation: 9 }, - { id: 14, first_name: "Loise", last_name: "Rivlin", email: "lrivlind@behance.net", shirt_size: "2XL", company_name: "Linktype", donation: 204 }, - { id: 15, first_name: "Christan", last_name: "Kendall", email: "ckendalle@example.com", shirt_size: "XS", company_name: "Skinix", donation: 252 }, - { id: 16, first_name: "Kayla", last_name: "Whitwam", email: "kwhitwamf@deliciousdays.com", shirt_size: "2XL", company_name: "Oyope", donation: 147 }, - { id: 17, first_name: "Heddie", last_name: "Heningam", email: "hheningamg@tripadvisor.com", shirt_size: "L", company_name: "Skinix", donation: 172 }, - { id: 18, first_name: "Mace", last_name: "Ballinger", email: "mballingerh@a8.net", shirt_size: "S", company_name: "Nlounge", donation: 266 }, - { id: 19, first_name: "Nola", last_name: "Abberley", email: "nabberleyi@jalbum.net", shirt_size: "XL", company_name: "Photospace", donation: 148 }, - { id: 20, first_name: "Nadine", last_name: "Tresler", email: "ntreslerj@marketwatch.com", shirt_size: "3XL", company_name: "Wikido", donation: 292 }, - { id: 21, first_name: "Ulrikaumeko", last_name: "Vuittet", email: "uvuittetk@gov.uk", shirt_size: "S", company_name: "Skinte", donation: 102 }, - { id: 22, first_name: "Saunder", last_name: "Spennock", email: "sspennockl@icq.com", shirt_size: "3XL", company_name: "Kwimbee", donation: 213 }, - { id: 23, first_name: "Carmel", last_name: "Woffinden", email: "cwoffindenm@wikispaces.com", shirt_size: "S", company_name: "Rooxo", donation: 137 }, - { id: 24, first_name: "Marielle", last_name: "Kimmel", email: "mkimmeln@jimdo.com", shirt_size: "M", company_name: "Livetube", donation: 96 }, - { id: 25, first_name: "Brucie", last_name: "Burris", email: "bburriso@slate.com", shirt_size: "2XL", company_name: "Wordtune", donation: 128 }, - { id: 26, first_name: "Juan", last_name: "Berzon", email: "jberzonp@soup.io", shirt_size: "3XL", company_name: "Einti", donation: 234 }, - { id: 27, first_name: "Sacha", last_name: "Olsen", email: "solsenq@reverbnation.com", shirt_size: "2XL", company_name: "Viva", donation: 190 }, - { id: 28, first_name: "Jamey", last_name: "O'Nolan", email: "jonolanr@samsung.com", shirt_size: "XL", company_name: "Skinix", donation: 31 }, - { id: 29, first_name: "Morrie", last_name: "Rainard", email: "mrainards@yale.edu", shirt_size: "XS", company_name: "Podcat", donation: 52 }, - { id: 30, first_name: "Fidel", last_name: "Roskelly", email: "froskellyt@ibm.com", shirt_size: "XS", company_name: "Avavee", donation: 5 }, - { id: 31, first_name: "Toni", last_name: "MacSweeney", email: "tmacsweeneyu@parallels.com", shirt_size: "M", company_name: "Jaloo", donation: 82 }, - { id: 32, first_name: "Jessey", last_name: "Walhedd", email: "jwalheddv@slashdot.org", shirt_size: "L", company_name: "Trilia", donation: 5 }, - { id: 33, first_name: "Karola", last_name: "Piper", email: "kpiperw@ucsd.edu", shirt_size: "3XL", company_name: "Yombu", donation: 110 }, - { id: 34, first_name: "Marley", last_name: "Mitchenson", email: "mmitchensonx@webeden.co.uk", shirt_size: "M", company_name: "Zoonoodle", donation: 97 }, - { id: 35, first_name: "Marrilee", last_name: "Thrasher", email: "mthrashery@opensource.org", shirt_size: "XL", company_name: "Bluejam", donation: 17 }, - { id: 36, first_name: "Tye", last_name: "Manie", email: "tmaniez@netscape.com", shirt_size: "L", company_name: "Kanoodle", donation: 30 }, - { id: 37, first_name: "Charleen", last_name: "Sheering", email: "csheering10@mit.edu", shirt_size: "3XL", company_name: "Jatri", donation: 262 }, - { id: 38, first_name: "Valma", last_name: "Eynaud", email: "veynaud11@archive.org", shirt_size: "XS", company_name: "Jaxbean", donation: 212 }, - { id: 39, first_name: "Dollie", last_name: "McDarmid", email: "dmcdarmid12@tinyurl.com", shirt_size: "S", company_name: "Kayveo", donation: 74 }, - { id: 40, first_name: "Minna", last_name: "Hymas", email: "mhymas13@cornell.edu", shirt_size: "XS", company_name: "Vimbo", donation: 101 }, - { id: 41, first_name: "Jsandye", last_name: "Frend", email: "jfrend14@ca.gov", shirt_size: "XS", company_name: "Latz", donation: 156 }, - { id: 42, first_name: "Yevette", last_name: "Hacket", email: "yhacket15@wp.com", shirt_size: "XL", company_name: "Lazzy", donation: 291 }, - { id: 43, first_name: "Hank", last_name: "Zebedee", email: "hzebedee16@ezinearticles.com", shirt_size: "L", company_name: "Gigashots", donation: 241 }, - { id: 44, first_name: "Jodie", last_name: "Stawell", email: "jstawell17@yale.edu", shirt_size: "S", company_name: "Jaxspan", donation: 262 }, - { id: 45, first_name: "Falito", last_name: "Karsh", email: "fkarsh18@pcworld.com", shirt_size: "S", company_name: "Mycat", donation: 239 }, - { id: 46, first_name: "Reginauld", last_name: "Purselowe", email: "rpurselowe19@thetimes.co.uk", shirt_size: "L", company_name: "Jabbersphere", donation: 11 }, - { id: 47, first_name: "Vida", last_name: "Tydd", email: "vtydd1a@dropbox.com", shirt_size: "S", company_name: "Quaxo", donation: 55 }, - { id: 48, first_name: "Anderea", last_name: "MacGiolla Pheadair", email: "amacgiollapheadair1b@xing.com", shirt_size: "2XL", company_name: "Kwimbee", donation: 214 }, - { id: 49, first_name: "Bel", last_name: "Alway", email: "balway1c@ow.ly", shirt_size: "S", company_name: "Voolia", donation: 107 }, - { id: 50, first_name: "Shell", last_name: "Baine", email: "sbaine1d@intel.com", shirt_size: "M", company_name: "Gabtype", donation: 171 }, - ]; - - // ==== Challenge 1: Use .forEach() ==== - // The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names and populate a new array called `fullNames`. This array will contain just strings. - let fullNames = []; - console.log(fullNames); - - // ==== Challenge 2: Use .map() ==== - // The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings. - let firstNamesAllCaps = []; - console.log(firstNamesAllCaps); - - // ==== Challenge 3: Use .filter() ==== - // The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects. - let runnersLargeSizeShirt = []; - console.log(runnersLargeSizeShirt); - - // ==== Challenge 4: Use .reduce() ==== - // The donations need to be tallied up and reported for tax purposes. Add up all the donations and save the total into a ticketPriceTotal variable. - let ticketPriceTotal = 0; - console.log(ticketPriceTotal); - - // ==== Challenge 5: Be Creative ==== - // Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above. - - // Problem 1 - + { id: 1, first_name: "Charmain", last_name: "Seiler", email: "cseiler0@wired.com", shirt_size: "2XL", company_name: "Divanoodle", donation: 75 }, + { id: 2, first_name: "Whitaker", last_name: "Ierland", email: "wierland1@angelfire.com", shirt_size: "2XL", company_name: "Wordtune", donation: 148 }, + { id: 3, first_name: "Julieta", last_name: "McCloid", email: "jmccloid2@yahoo.com", shirt_size: "S", company_name: "Riffpedia", donation: 171 }, + { id: 4, first_name: "Martynne", last_name: "Paye", email: "mpaye3@sciencedaily.com", shirt_size: "XL", company_name: "Wordware", donation: 288 }, + { id: 5, first_name: "Gussy", last_name: "Raraty", email: "graraty4@ucoz.ru", shirt_size: "L", company_name: "Oozz", donation: 291 }, + { id: 6, first_name: "Yule", last_name: "Tommasetti", email: "ytommasetti5@state.gov", shirt_size: "S", company_name: "Yodo", donation: 27 }, + { id: 7, first_name: "Kathie", last_name: "Majury", email: "kmajury6@guardian.co.uk", shirt_size: "3XL", company_name: "Zoomcast", donation: 261 }, + { id: 8, first_name: "Tanner", last_name: "Branton", email: "tbranton7@tmall.com", shirt_size: "2XL", company_name: "Realmix", donation: 28 }, + { id: 9, first_name: "Sarina", last_name: "Lasham", email: "slasham8@toplist.cz", shirt_size: "XL", company_name: "Gigashots", donation: 110 }, + { id: 10, first_name: "Bertie", last_name: "Lonergan", email: "blonergan9@issuu.com", shirt_size: "3XL", company_name: "Skinte", donation: 62 }, + { id: 11, first_name: "Trevor", last_name: "Studd", email: "tstudda@networkadvertising.org", shirt_size: "S", company_name: "Cogidoo", donation: 76 }, + { id: 12, first_name: "Malachi", last_name: "Okeshott", email: "mokeshottb@chron.com", shirt_size: "M", company_name: "DabZ", donation: 91 }, + { id: 13, first_name: "Berget", last_name: "Logsdail", email: "blogsdailc@wix.com", shirt_size: "M", company_name: "Mymm", donation: 9 }, + { id: 14, first_name: "Loise", last_name: "Rivlin", email: "lrivlind@behance.net", shirt_size: "2XL", company_name: "Linktype", donation: 204 }, + { id: 15, first_name: "Christan", last_name: "Kendall", email: "ckendalle@example.com", shirt_size: "XS", company_name: "Skinix", donation: 252 }, + { id: 16, first_name: "Kayla", last_name: "Whitwam", email: "kwhitwamf@deliciousdays.com", shirt_size: "2XL", company_name: "Oyope", donation: 147 }, + { id: 17, first_name: "Heddie", last_name: "Heningam", email: "hheningamg@tripadvisor.com", shirt_size: "L", company_name: "Skinix", donation: 172 }, + { id: 18, first_name: "Mace", last_name: "Ballinger", email: "mballingerh@a8.net", shirt_size: "S", company_name: "Nlounge", donation: 266 }, + { id: 19, first_name: "Nola", last_name: "Abberley", email: "nabberleyi@jalbum.net", shirt_size: "XL", company_name: "Photospace", donation: 148 }, + { id: 20, first_name: "Nadine", last_name: "Tresler", email: "ntreslerj@marketwatch.com", shirt_size: "3XL", company_name: "Wikido", donation: 292 }, + { id: 21, first_name: "Ulrikaumeko", last_name: "Vuittet", email: "uvuittetk@gov.uk", shirt_size: "S", company_name: "Skinte", donation: 102 }, + { id: 22, first_name: "Saunder", last_name: "Spennock", email: "sspennockl@icq.com", shirt_size: "3XL", company_name: "Kwimbee", donation: 213 }, + { id: 23, first_name: "Carmel", last_name: "Woffinden", email: "cwoffindenm@wikispaces.com", shirt_size: "S", company_name: "Rooxo", donation: 137 }, + { id: 24, first_name: "Marielle", last_name: "Kimmel", email: "mkimmeln@jimdo.com", shirt_size: "M", company_name: "Livetube", donation: 96 }, + { id: 25, first_name: "Brucie", last_name: "Burris", email: "bburriso@slate.com", shirt_size: "2XL", company_name: "Wordtune", donation: 128 }, + { id: 26, first_name: "Juan", last_name: "Berzon", email: "jberzonp@soup.io", shirt_size: "3XL", company_name: "Einti", donation: 234 }, + { id: 27, first_name: "Sacha", last_name: "Olsen", email: "solsenq@reverbnation.com", shirt_size: "2XL", company_name: "Viva", donation: 190 }, + { id: 28, first_name: "Jamey", last_name: "O'Nolan", email: "jonolanr@samsung.com", shirt_size: "XL", company_name: "Skinix", donation: 31 }, + { id: 29, first_name: "Morrie", last_name: "Rainard", email: "mrainards@yale.edu", shirt_size: "XS", company_name: "Podcat", donation: 52 }, + { id: 30, first_name: "Fidel", last_name: "Roskelly", email: "froskellyt@ibm.com", shirt_size: "XS", company_name: "Avavee", donation: 5 }, + { id: 31, first_name: "Toni", last_name: "MacSweeney", email: "tmacsweeneyu@parallels.com", shirt_size: "M", company_name: "Jaloo", donation: 82 }, + { id: 32, first_name: "Jessey", last_name: "Walhedd", email: "jwalheddv@slashdot.org", shirt_size: "L", company_name: "Trilia", donation: 5 }, + { id: 33, first_name: "Karola", last_name: "Piper", email: "kpiperw@ucsd.edu", shirt_size: "3XL", company_name: "Yombu", donation: 110 }, + { id: 34, first_name: "Marley", last_name: "Mitchenson", email: "mmitchensonx@webeden.co.uk", shirt_size: "M", company_name: "Zoonoodle", donation: 97 }, + { id: 35, first_name: "Marrilee", last_name: "Thrasher", email: "mthrashery@opensource.org", shirt_size: "XL", company_name: "Bluejam", donation: 17 }, + { id: 36, first_name: "Tye", last_name: "Manie", email: "tmaniez@netscape.com", shirt_size: "L", company_name: "Kanoodle", donation: 30 }, + { id: 37, first_name: "Charleen", last_name: "Sheering", email: "csheering10@mit.edu", shirt_size: "3XL", company_name: "Jatri", donation: 262 }, + { id: 38, first_name: "Valma", last_name: "Eynaud", email: "veynaud11@archive.org", shirt_size: "XS", company_name: "Jaxbean", donation: 212 }, + { id: 39, first_name: "Dollie", last_name: "McDarmid", email: "dmcdarmid12@tinyurl.com", shirt_size: "S", company_name: "Kayveo", donation: 74 }, + { id: 40, first_name: "Minna", last_name: "Hymas", email: "mhymas13@cornell.edu", shirt_size: "XS", company_name: "Vimbo", donation: 101 }, + { id: 41, first_name: "Jsandye", last_name: "Frend", email: "jfrend14@ca.gov", shirt_size: "XS", company_name: "Latz", donation: 156 }, + { id: 42, first_name: "Yevette", last_name: "Hacket", email: "yhacket15@wp.com", shirt_size: "XL", company_name: "Lazzy", donation: 291 }, + { id: 43, first_name: "Hank", last_name: "Zebedee", email: "hzebedee16@ezinearticles.com", shirt_size: "L", company_name: "Gigashots", donation: 241 }, + { id: 44, first_name: "Jodie", last_name: "Stawell", email: "jstawell17@yale.edu", shirt_size: "S", company_name: "Jaxspan", donation: 262 }, + { id: 45, first_name: "Falito", last_name: "Karsh", email: "fkarsh18@pcworld.com", shirt_size: "S", company_name: "Mycat", donation: 239 }, + { id: 46, first_name: "Reginauld", last_name: "Purselowe", email: "rpurselowe19@thetimes.co.uk", shirt_size: "L", company_name: "Jabbersphere", donation: 11 }, + { id: 47, first_name: "Vida", last_name: "Tydd", email: "vtydd1a@dropbox.com", shirt_size: "S", company_name: "Quaxo", donation: 55 }, + { id: 48, first_name: "Anderea", last_name: "MacGiolla Pheadair", email: "amacgiollapheadair1b@xing.com", shirt_size: "2XL", company_name: "Kwimbee", donation: 214 }, + { id: 49, first_name: "Bel", last_name: "Alway", email: "balway1c@ow.ly", shirt_size: "S", company_name: "Voolia", donation: 107 }, + { id: 50, first_name: "Shell", last_name: "Baine", email: "sbaine1d@intel.com", shirt_size: "M", company_name: "Gabtype", donation: 171 }, +]; + +// ==== Challenge 1: Use .forEach() ==== +// The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names and populate a new array called `fullNames`. This array will contain just strings. +let fullNames = []; +runners.forEach(function (object) { + let name = object.first_name + " " + object.last_name; + fullNames.push(name) +}) +console.log(fullNames); + +// ==== Challenge 2: Use .map() ==== +// The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings. +let firstNamesAllCaps = []; +firstNamesAllCaps = runners.map(runner => { + return runner["first_name"].toUpperCase(); +}) +console.log(firstNamesAllCaps); + +// ==== Challenge 3: Use .filter() ==== +// The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects. +let runnersLargeSizeShirt = []; +runnersLargeSizeShirt = runners.filter(runner => runner["shirt_size"] === "L") + +console.log(runnersLargeSizeShirt); + +// ==== Challenge 4: Use .reduce() ==== +// The donations need to be tallied up and reported for tax purposes. Add up all the donations and save the total into a ticketPriceTotal variable. +let ticketPriceTotal = runners.reduce((donation, total, index, runners) => { + return donation += total.donation +}, 0); +console.log(ticketPriceTotal); + +// ==== Challenge 5: Be Creative ==== +// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to create and then solve 3 unique problems using one or many of the array methods listed above. + +// Problem 1 +let findKwimbee = runners.filter((KwimbeeCo) => { + return KwimbeeCo.company_name === "Kwimbee" +}); + +findKwimbee.company_name = "QueenBee" +console.log(findKwimbee); // Problem 2 - + // Problem 3 \ No newline at end of file diff --git a/week 1/4-prototypes.js b/week 1/4-prototypes.js index 02f6821..78a4bab 100644 --- a/week 1/4-prototypes.js +++ b/week 1/4-prototypes.js @@ -5,26 +5,38 @@ /* == Step 1: Base Constructor == Create a constructor function named CuboidMaker that accepts properties for length, width, and height */ - +function CuboidMaker(length, width, height) { + this.length = length; + this.width = width; + this.height = height + +} /* == Step 2: Volume Method == Create a method using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height Formula for cuboid volume: length * width * height */ - +CuboidMaker.prototype.volume = function () { + return this.length * this.width * this.height; +}; /* == Step 3: Surface Area Method == Create another method using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height. Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) */ - +CuboidMaker.prototype.surface_area = function () { + return 2 * (this.length * this.width + this.length * this.height + this.width * this.height); + +}; /* == Step 4: Create a new object that uses CuboidMaker == Create a cuboid object that uses the new keyword to use our CuboidMaker constructor Add properties and values of length: 4, width: 5, and height: 5 to cuboid. */ - +let cuboid = new CuboidMaker( 4, 5, 5); // Test your volume and surfaceArea methods by uncommenting the logs below: // console.log(cuboid.volume()); // 100 -// console.log(cuboid.surfaceArea()); // 130 \ No newline at end of file +// console.log(cuboid.surfaceArea()); // 130 +console.log(cuboid.volume()); +console.log(cuboid.surface_area()); \ No newline at end of file From da845c60ca79c7dac7d816a407efc0390d832eb5 Mon Sep 17 00:00:00 2001 From: Ojediran Gbemisola Date: Sun, 5 Jul 2020 17:52:24 +0100 Subject: [PATCH 2/2] My todolist and Calculator --- week 1/5-classes.js | 22 +++++++++- week3_4/Calculator/index.css | 35 +++++++++++++++ week3_4/Calculator/index.html | 51 ++++++++++++++++++++++ week3_4/Calculator/index.js | 19 +++++++++ week3_4/Todolist/todolist.css | 78 ++++++++++++++++++++++++++++++++++ week3_4/Todolist/todolist.html | 34 +++++++++++++++ week3_4/Todolist/todolist.js | 42 ++++++++++++++++++ 7 files changed, 280 insertions(+), 1 deletion(-) create mode 100644 week3_4/Calculator/index.css create mode 100644 week3_4/Calculator/index.html create mode 100644 week3_4/Calculator/index.js create mode 100644 week3_4/Todolist/todolist.css create mode 100644 week3_4/Todolist/todolist.html create mode 100644 week3_4/Todolist/todolist.js diff --git a/week 1/5-classes.js b/week 1/5-classes.js index 0512bc7..231c5de 100644 --- a/week 1/5-classes.js +++ b/week 1/5-classes.js @@ -1,6 +1,26 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. +class CuboidMaker { + constructor (attributes) { + this.length = attributes.length; + this.width = attributes.width; + this.height = attributes.height; + } + volume() { + return this.length * this.width * this.height; + } + surfaceArea() { + return 2 * (this.length * this.width + this.length * this.height + this.width * this.height); + } + } + + const cuboid = new CuboidMaker ({ + "length": 4, + "width": 5, + "height": 5, + }); // Test your volume and surfaceArea methods by uncommenting the logs below: // console.log(cuboid.volume()); // 100 // console.log(cuboid.surfaceArea()); // 130 - +console.log(cuboid.volume()); +console.log(cuboid.surface_area()); diff --git a/week3_4/Calculator/index.css b/week3_4/Calculator/index.css new file mode 100644 index 0000000..5af551c --- /dev/null +++ b/week3_4/Calculator/index.css @@ -0,0 +1,35 @@ +*{ + margin: 0px; + padding: 0px; +} +.button{ + width: 50px; + height: 50px; + font-size: 25px; + margin: 2px; + cursor: pointer; +} +.textarea{ + width: 207px; + margin: 5px; + font-size: 25px; + padding: 3px; +} +body{ + + display: flex; + flex-direction: column; + align-items: center; + padding-top: 50px; + } + .box{ + width: 300px; + border: 15px solid gainsboro; + border-radius: 10px; + padding: 50px; + margin: 20px; + } + h1{ + font-style: italic; + } + \ No newline at end of file diff --git a/week3_4/Calculator/index.html b/week3_4/Calculator/index.html new file mode 100644 index 0000000..05e1e75 --- /dev/null +++ b/week3_4/Calculator/index.html @@ -0,0 +1,51 @@ + + + + + + + + + + +
+

Gbemi's Calc

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + \ No newline at end of file diff --git a/week3_4/Calculator/index.js b/week3_4/Calculator/index.js new file mode 100644 index 0000000..0ef9c2a --- /dev/null +++ b/week3_4/Calculator/index.js @@ -0,0 +1,19 @@ +function insert(num){ + document.form.textarea.value = document.form.textarea.value + num +} + +function equal(){ + var exp = document.form.textarea.value; + if(exp){ + document.form.textarea.value = eval(exp) + } +} + +function clean(){ + document.form.textarea.value = ""; +} + +function back(){ + var exp = document.form.textarea.value; + document.form.textarea.value = exp.substring(0, exp.length-1); +} \ No newline at end of file diff --git a/week3_4/Todolist/todolist.css b/week3_4/Todolist/todolist.css new file mode 100644 index 0000000..b820a35 --- /dev/null +++ b/week3_4/Todolist/todolist.css @@ -0,0 +1,78 @@ +body{ + + display: flex; + flex-direction: column; + align-items: center; +} +.box{ + width: 300px; + border: 15px solid gainsboro; + border-radius: 10px; + padding: 50px; + margin: 20px; +} +.header{ + padding-bottom: 20px; +} +h1{ + font-style: italic; +} +input{ + font-style: italic; + font-size: 15px; +} +ol li { + cursor: pointer; + position: relative; + padding-top: 15px; + padding-right: 15px; + padding-bottom: 15px; + padding-left: 15px; + background: gray; + font-size: 18px; + transition: 0.2s; +} +ol#myList{ + background: rgba(46, 41, 41, 0.747); +} + +ol li:hover { + background: rgb(230, 214, 214); + } +ol li.checked { + background: #888; + color: #fff; + text-decoration: line-through; + } + + .addBtn { + padding: 10px; + width: 25%; + background: #d9d9d9; + color: #555; + float: inline-end; + text-align: center; + font-size: 16px; + cursor: pointer; + transition: 0.3s; + border-radius: 0; + + } + + .addBtn:hover { + background-color: rgb(230, 214, 214); + } + #myInput{ + padding: 12px 8px 12px 40px; + } + .close { + position: absolute; + right: 0; + top: 0; + padding: 12px 16px 12px 16px; + } + + .close:hover { + background-color: #f44336; + color: white; + } \ No newline at end of file diff --git a/week3_4/Todolist/todolist.html b/week3_4/Todolist/todolist.html new file mode 100644 index 0000000..df39cba --- /dev/null +++ b/week3_4/Todolist/todolist.html @@ -0,0 +1,34 @@ + + + + + My To-Do List + + + + + + + +
+
+

Gbemi's To-Do List

+ + Add +
+ +
+
    +
  1. Wake Up
  2. +
  3. Do Chores
  4. +
  5. Read
  6. +
  7. Dance Practice
  8. +
  9. Dinner
  10. +
+
+
+ + + + + \ No newline at end of file diff --git a/week3_4/Todolist/todolist.js b/week3_4/Todolist/todolist.js new file mode 100644 index 0000000..eaa6c8a --- /dev/null +++ b/week3_4/Todolist/todolist.js @@ -0,0 +1,42 @@ +//close button +var MyList = document.getElementsByTagName('li'); +var index; +for(index = 0; index < MyList.length; index++){ + var aSpanTag = document.createElement("SPAN"); + var someTxt = document.createTextNode("\u00D7"); + aSpanTag.className = "close"; + aSpanTag.appendChild(someTxt); + MyList[index].appendChild(aSpanTag); +} + + +var closeButton = document.getElementsByClassName("close"); +for(i = 0; i < closeButton.length; i++){ + closeButton[i].onclick = function(){ + var theDiv = this.parentElement; + theDiv.style.display = "none"; + } +} +//Adding to the list +function createNewElement(){ + var li = document.createElement('li'); + var theInputValue = document.getElementById("myInput").value; + var textNode = document.createTextNode(theInputValue); + li.appendChild(textNode); + + if (theInputValue === '') { + alert("It is empty, write something") + } else { + document.getElementById("myList").appendChild(li); + } + document.getElementById("myInput").value = ""; + + var thePanTag = document.createElement("SPAN"); + var txt = document.createTextNode("\u00D7"); + thePanTag.className = "close"; + thePanTag.appendChild(txt); + li.appendChild(thePanTag); + + +} +