diff --git a/week 1/1-objects.js b/week 1/1-objects.js index 23d4324..4687451 100644 --- a/week 1/1-objects.js +++ b/week 1/1-objects.js @@ -1,43 +1,88 @@ -// Let's get some practice writing a few objects for a new group of interns at a small business. - -// ==== Challenge 1: Writing Objects ==== -// HR needs some information on the new interns put into a database. Given an id, email, first name, and gender. Create an object for each person in the company list: - -// 1, mmelloy0@psu.edu, Mitzi, F -// 2, kdiben1@tinypic.com, Kennan, M -// 3, kmummery2@wikimedia.org, Keven, M -// 4, gmartinson3@illinois.edu, Gannie, M -// 5, adaine5@samsung.com, Antonietta, F - -// Example format of an intern object: 1, examples@you.edu, Example, F -const example = { - id: 0, - name: "Example", - email: "examples@you.edu", - gender: "M", - } - - // Write your intern objects here: - - - // ==== Challenge 2: Reading Object Data ==== - // Once your objects are created, log out the following requests from HR into the console: - - // Mitzi's name - - // Kennan's ID - - // Keven's email - - // Gannie's name - - // Antonietta's 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()); - - // 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)); - +// Let's get some practice writing a few objects for a new group of interns at a small business. + +// ==== Challenge 1: Writing Objects ==== +// HR needs some information on the new interns put into a database. Given an id, email, first name, and gender. Create an object for each person in the company list: + +// 1, mmelloy0@psu.edu, Mitzi, F +// 2, kdiben1@tinypic.com, Kennan, M +// 3, kmummery2@wikimedia.org, Keven, M +// 4, gmartinson3@illinois.edu, Gannie, M +// 5, adaine5@samsung.com, Antonietta, F + +// Example format of an intern object: 1, examples@you.edu, Example, F +const example = { + id: 0, + name: "Example", + email: "examples@you.edu", + gender: "M", + } + + // Write your intern objects here: + + const intern_1 = { + id: 1, + name: "Mitzi", + email: "mmelloy0@psu.edu", + gender: "F", + } + + const intern_2 = { + id: 2, + name: "Kennan", + email: "kdiben1@tinypic.com", + gender: "M", + } + + const intern_3 = { + id: 3, + name: "Keven", + email: "kmummery2@wikimedia.org", + gender: "M", + } + + const intern_4 = { + id: 4, + name: "Gannie", + email: "gmartinson3@illinois.edu", + gender: "M", + } + + const intern_5 = { + id: 5, + name: "Antonietta", + email: "adaine5@samsung.com", + gender: "F", + } + // ==== 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(intern_1.name); + + // Kennan's ID + console.log(intern_2.id); + + // Keven's email + console.log(intern_3.email); + + // Gannie's name + console.log(intern_4.name); + + // Antonietta's Gender + console.log(intern_5.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()); + intern_2.speak = function() { + return `Hello, my name is ${this.name} !`; + } + + // 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)); + intern_5.multiplyNums = function(num1, num2) { + return num1 * num2; + } + \ No newline at end of file diff --git a/week 1/2-arrays.js b/week 1/2-arrays.js index e228146..56fdcb0 100644 --- a/week 1/2-arrays.js +++ b/week 1/2-arrays.js @@ -1,105 +1,110 @@ -// Note: Make use of for loops in solving the challenges in this file -// To help us use arrays with real world problems we are going to simulate a used car dealer that has 50 cars in their inventory. - -// The car dealer has all of their inventory housed in the array seen below. Scroll down past the data to find out how you can help the car dealer. - -let inventory = [ - { id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 }, - { id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 }, - { id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 }, - { id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 }, - { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, - { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, - { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, - { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, - { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, - { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, - { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, - { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, - { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 }, - { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 }, - { id: 15, car_make: "Dodge", car_model: "Intrepid", car_year: 2000 }, - { id: 16, car_make: "Mitsubishi", car_model: "Montero Sport", car_year: 2001 }, - { id: 17, car_make: "Buick", car_model: "Skylark", car_year: 1987 }, - { id: 18, car_make: "Geo", car_model: "Prizm", car_year: 1995 }, - { id: 19, car_make: "Oldsmobile", car_model: "Bravada", car_year: 1994 }, - { id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 }, - { id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 }, - { id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 }, - { id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 }, - { id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 }, - { id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, - { id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 }, - { id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 }, - { id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 }, - { id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 }, - { id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, - { id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 }, - { id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 }, - { id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 }, - { id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 }, - { id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 }, - { id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 }, - { id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 }, - { id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 }, - { id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 }, - { id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 }, - { id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 }, - { id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 }, - { id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 }, - { id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, - { id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, - { id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 }, - { id: 47, car_make: "Volkswagen", car_model: "Jetta", car_year: 2007 }, - { id: 48, car_make: "Dodge", car_model: "Magnum", car_year: 2008 }, - { id: 49, car_make: "Chrysler", car_model: "Sebring", car_year: 1996 }, - { id: 50, car_make: "Lincoln", car_model: "Town Car", car_year: 1999 } - ]; - - // Example 1 for loop: - - // const arr = ['a', 'b', 'c', 'd']; - // for (let i = 0; i < arr.length; i++) { - // console.log(arr[i]); - // } - // 'a' 'b' 'c' 'd' - - // Example 2 for loop: - - // const arr = [12, 13, 14, 15]; - // const evens = []; - // for (let i = 0; i < arr.length; i++) { - // if (arr[i] % 2 === 0) { evens.push(arr[i]); } - // } - // console.log(evens); - // [12, 14] - - // ==== 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*`); - - // ==== 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(); - - // ==== 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(); - - // ==== 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(); - - // ==== 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(); - - // ==== 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 +// Note: Make use of for loops in solving the challenges in this file +// To help us use arrays with real world problems we are going to simulate a used car dealer that has 50 cars in their inventory. + +// The car dealer has all of their inventory housed in the array seen below. Scroll down past the data to find out how you can help the car dealer. + +let inventory = [ + { id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 }, + { id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 }, + { id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 }, + { id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 }, + { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, + { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, + { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, + { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, + { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, + { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, + { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, + { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, + { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 }, + { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 }, + { id: 15, car_make: "Dodge", car_model: "Intrepid", car_year: 2000 }, + { id: 16, car_make: "Mitsubishi", car_model: "Montero Sport", car_year: 2001 }, + { id: 17, car_make: "Buick", car_model: "Skylark", car_year: 1987 }, + { id: 18, car_make: "Geo", car_model: "Prizm", car_year: 1995 }, + { id: 19, car_make: "Oldsmobile", car_model: "Bravada", car_year: 1994 }, + { id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 }, + { id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 }, + { id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 }, + { id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 }, + { id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 }, + { id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, + { id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 }, + { id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 }, + { id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 }, + { id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 }, + { id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, + { id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 }, + { id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 }, + { id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 }, + { id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 }, + { id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 }, + { id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 }, + { id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 }, + { id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 }, + { id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 }, + { id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 }, + { id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 }, + { id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 }, + { id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 }, + { id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, + { id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, + { id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 }, + { id: 47, car_make: "Volkswagen", car_model: "Jetta", car_year: 2007 }, + { id: 48, car_make: "Dodge", car_model: "Magnum", car_year: 2008 }, + { id: 49, car_make: "Chrysler", car_model: "Sebring", car_year: 1996 }, + { id: 50, car_make: "Lincoln", car_model: "Town Car", car_year: 1999 } + ]; + + // Example 1 for loop: + + // const arr = ['a', 'b', 'c', 'd']; + // for (let i = 0; i < arr.length; i++) { + // console.log(arr[i]); + // } + // 'a' 'b' 'c' 'd' + + // Example 2 for loop: + + // const arr = [12, 13, 14, 15]; + // const evens = []; + // for (let i = 0; i < arr.length; i++) { + // if (arr[i] % 2 === 0) { evens.push(arr[i]); } + // } + // console.log(evens); + // [12, 14] + + // ==== 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*`); + inventory.forEach(car => { + if(car.id === 33) { + console.log(`Car ${car.id} is a ${car.car_year} ${car.car_model}`); + } + }); + + // ==== 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 = inventory[inventory.length - 1]; + console.log(`${lastCar.car_make} ${lastCar.car_model}`); + + // ==== 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 = inventory.map(car => car.car_model); + let carModelsSorted = carModels.sort(); + console.log(carModelsSorted); + + // ==== 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 = inventory.map(car => car.car_year); + 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 = inventory.filter(car => car.car_year < 2000); + 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 = inventory.filter(car => car.car_make === 'BMW' || car.car_make === 'Audi'); + 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..1e6167e 100644 --- a/week 1/3-array-methods.js +++ b/week 1/3-array-methods.js @@ -1,85 +1,121 @@ -// A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation. - -// 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 - - // Problem 2 - - // Problem 3 \ No newline at end of file +// A local community center is holding a fund raising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation. + +// 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 = []; + runners.forEach(runner => { + fullNames.push(`${runner.first_name} ${runner.last_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 = runners.map(runner => 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 = 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((acc,runner) => acc + runner.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: + // .filter() -- return the even/odd numbers in an array containing numbers + function findEvenAndOdd(array) { + let evenNums = array.filter(number => typeof number === 'number' && number % 2 === 0); + let oddNums = array.filter(number => typeof number === 'number' && number % 2 !== 0); + return {evenNums, oddNums}; + } + + const nums = [1,2,3,'bananas',4,5,'apricot',6,'apples',7,8,9,10]; + console.log(findEvenAndOdd(nums)); + + + // Problem 2: + // .map() -- element-wise multiplication of two number arrays + function elementMultiply(arr1, arr2) { + if(arr1.length === arr2.length) { + return arr1.map((num, ind) => num * arr2[ind]); + } else { + return "Arrays are not of matching dimensions!"; + } + } + + const numSet1 = [1, 2, 3, 3]; + const numSet2 = [5, 4, 2, 1]; + console.log(elementMultiply(numSet1, numSet2)); // [5, 8, 6, 3] + + + // Problem 3: + // .forEach() -- reverse a string + function reverseString(str) { + let reversed = ''; + str.split('').forEach(char => { + reversed = char + reversed; + }); + return reversed; + } + + console.log(reverseString('fork')); \ No newline at end of file diff --git a/week 1/4-prototypes.js b/week 1/4-prototypes.js index 02f6821..ea8c503 100644 --- a/week 1/4-prototypes.js +++ b/week 1/4-prototypes.js @@ -1,30 +1,41 @@ -/* ===== Prototype Practice ===== */ - -// Task: You are to build a cuboid maker that can return values for a cuboid's volume or surface area. Cuboids are similar to cubes but do not have even sides. Follow the steps in order to accomplish this challenge. - -/* == Step 1: Base Constructor == - Create a constructor function named CuboidMaker that accepts properties for length, width, and 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 -*/ - - -/* == 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) -*/ - - -/* == 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. -*/ - -// 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 +/* ===== Prototype Practice ===== */ + +// Task: You are to build a cuboid maker that can return values for a cuboid's volume or surface area. Cuboids are similar to cubes but do not have even sides. Follow the steps in order to accomplish this challenge. + +/* == 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.surfaceArea = 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. +*/ +const 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 diff --git a/week 1/5-classes.js b/week 1/5-classes.js index 0512bc7..0b8b239 100644 --- a/week 1/5-classes.js +++ b/week 1/5-classes.js @@ -1,6 +1,23 @@ -// 1. Copy and paste your prototype in here and refactor into class syntax. - -// Test your volume and surfaceArea methods by uncommenting the logs below: -// console.log(cuboid.volume()); // 100 -// console.log(cuboid.surfaceArea()); // 130 - +// 1. Copy and paste your prototype in here and refactor into class syntax. +class CuboidMaker { + constructor(length, width, height) { + this.length = length; + this.width = width; + this.height = 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(4, 5, 5); + +// Test your volume and surfaceArea methods by uncommenting the logs below: +console.log(cuboid.volume()); // 100 +console.log(cuboid.surfaceArea()); // 130 +