From 26a21c308098b21113735892b1ecf782abb2a347 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 1 Oct 2019 23:01:20 -0500 Subject: [PATCH 1/4] forked --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23108974b..a54164dc7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **Follow these steps to set up and work on your project:** -- [ ] Create a forked copy of this project. +- [/ ] Create a forked copy of this project. - [ ] Add your team lead as collaborator on Github. - [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). - [ ] Create a new branch: git checkout -b ``. From e388b5e0e3e4053f40a099df91abb2326fe158ff Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 1 Oct 2019 23:46:02 -0500 Subject: [PATCH 2/4] objects are done --- assignments/objects.js | 123 ++++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 46 deletions(-) diff --git a/assignments/objects.js b/assignments/objects.js index 798d5e0cf..8080334c1 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -1,64 +1,95 @@ -// Let's get some practice writing a few objects for a new group of interns at a small business. +//* 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: +//* ==== 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 +// *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 +//* Example format of an intern object: 1, examples@you.edu, Example, F const example = { id: 0, name: "Example", email: "examples@you.edu", - gender: "F", -} + gender: "F" +}; -// 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. +// *Write your intern objects here: +const internOne = { + id: 0, + name: "Mitzi", + email: "kdiben1@PushSubscription.edu", + gender: "f" +}; +const internTwo = { + id: 1, + name: "Kennan", + email: "kdiben1@tinypic.com", + gender: "M" +}; +const internThree = { + id: 2, + name: "Keven", + email: "kmimmery2@wikimedia.org", + gender: "M" +}; + +const internFour = { + id: 3, + name: "Gannie", + email: "gmartinson3@illinois.edu", + gender: "M" +}; +const internFive = { + id: 4, + 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(internOne.name); +// *Kennan's ID +console.log(internTwo.id); +// *Keven's email +console.log(internThree.email); +// *Gannie's name +console.log(internFour.name); +// *Antonietta's Gender +console.log(internFive.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 = "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=(3,4)"); +//* === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. -// === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. - -// ==== Stretch Challenge: Nested Objects and the this keyword ==== +// !==== Stretch Challenge: Nested Objects and the this keyword ==== -// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70. -// 2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50. -// 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30 -// 4. Give each of the objects the ability to speak their names using the this keyword. +// !1. Create a parent object with properties for name and age. Make the name Susan and the age 70. +// !2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50. +//! 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30 +//! 4. Give each of the objects the ability to speak their names using the this keyword. -const parent = {} +const parent = {}; -// Log the parent object's name +//* Log the parent object's name -// Log the child's age +//* Log the child's age -// Log the name and age of the grandchild +//* Log the name and age of the grandchild -// Have the parent speak +//* Have the parent speak -// Have the child speak +//* Have the child speak -// Have the grandchild speak +//* Have the grandchild speak From a1900b45b3aeff63647e1810f6b8d525dbe626a4 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 2 Oct 2019 20:25:06 -0500 Subject: [PATCH 3/4] update --- assignments/arrays.js | 64 +++++++++++++++++++++++++++++++----------- assignments/objects.js | 1 + 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 1dbf8bd35..abe3a2c46 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -5,7 +5,12 @@ 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: 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 }, @@ -18,7 +23,12 @@ let inventory = [ { 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: 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 }, @@ -73,32 +83,52 @@ let inventory = [ // console.log(evens); // [12, 14] -// ==== Challenge 1 ==== +//* ==== 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 ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].car_model}` +); -// ==== Challenge 2 ==== +//* ==== 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 = inventory[inventory.length - 1]; +console.log( + `The last car in our inventory is a ${lastCar.car_make} ${lastCar.car_model}` +); -// ==== 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(); +inventory + .sort((a, b) => { + return a.car_model < b.car_model ? -1 : 1; + }) + .forEach(car => { + carModelsSorted.push(car.car_model); + }); -// ==== Challenge 4 ==== +console.table(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 = []; -console.log(); +inventory.forEach(car => { + carYears.push(car.car_year); +}); +console.log(carYears); -// ==== Challenge 5 ==== +//* ==== 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 = carYears.filter(year => year < 2000); +console.log(oldCars.length); -// ==== Challenge 6 ==== +//* ==== 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(); +let BMWAndAudi = inventory.filter(car => { + if (car.car_make === "BMW" || car.car_make === "Audi") { + return car; + } +}); + +console.log(JSON.stringify(BMWAndAudi)); diff --git a/assignments/objects.js b/assignments/objects.js index 8080334c1..a7feee965 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -71,6 +71,7 @@ console.log((Kennan = "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=(3,4)"); + //* === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. // !==== Stretch Challenge: Nested Objects and the this keyword ==== From 5166f07fda7da14f5ee97e849bd5ec2e98b0b0bc Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 6 Oct 2019 20:12:29 -0500 Subject: [PATCH 4/4] finished --- assignments/arrays.js | 44 +++++++------- assignments/function-conversion.js | 45 ++++++++------ assignments/objects.js | 95 +++++++++++++++--------------- 3 files changed, 96 insertions(+), 88 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index abe3a2c46..f59e0175a 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -1,6 +1,6 @@ -// 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. +//* 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. +//* 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 }, @@ -65,39 +65,39 @@ let inventory = [ { id: 50, car_make: "Lincoln", car_model: "Town Car", car_year: 1999 } ]; -// Example 1 for loop: +//* 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' +//* 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: +//* 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] +//* 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: +//* 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 ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].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. +//* 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( `The last car in our inventory is a ${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 +//* 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 = []; inventory @@ -111,7 +111,7 @@ inventory console.table(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. +//* 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.forEach(car => { carYears.push(car.car_year); @@ -119,12 +119,12 @@ inventory.forEach(car => { 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. +//* 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 = carYears.filter(year => 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. +//* 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 => { if (car.car_make === "BMW" || car.car_make === "Audi") { return car; diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 55f57ef62..f5f624232 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -1,25 +1,32 @@ -// Take the commented ES5 syntax and convert it to ES6 arrow Syntax +//* Take the commented ES5 syntax and convert it to ES6 arrow Syntax -// let myFunction = function () { -// console.log("Function was invoked!"); -// }; -// myFunction(); +//* let myFunction = function () { +//* console.log("Function was invoked!"); +//* }; +//* myFunction(); +const myFunction = () => console.log("Function was invoked!"); +myFunction(); -// let anotherFunction = function (param) { -// return param; -// }; -// anotherFunction("Example"); +//* let anotherFunction = function (param) { +//* return param; +//* }; +//* anotherFunction("Example"); +const anotherFunction = param => param; +console.log(anotherFunction("Example")); -// let add = function (param1, param2) { -// return param1 + param2; -// }; -// add(1,2); - -// let subtract = function (param1, param2) { -// return param1 - param2; -// }; -// subtract(1,2); +//* let add = function (param1, param2) { +//* return param1 + param2; +//* }; +//* add(1,2); +const add = (param1, param2) => param1 + param2; +console.log(add(1, 2)); +//* let subtract = function (param1, param2) { +//* return param1 - param2; +//* }; +//* subtract(1,2); +const subtract = (param1, param2) => param1 - param2; +console.log(subtract(1, 2)); // Stretch @@ -27,4 +34,4 @@ // const triple = exampleArray.map(function (num) { // return num * 3; // }); -// console.log(triple); \ No newline at end of file +// console.log(triple); diff --git a/assignments/objects.js b/assignments/objects.js index a7feee965..975176722 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -3,11 +3,11 @@ //* ==== 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 +//* 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 = { @@ -17,62 +17,65 @@ const example = { gender: "F" }; -// *Write your intern objects here: -const internOne = { - id: 0, - name: "Mitzi", - email: "kdiben1@PushSubscription.edu", - gender: "f" -}; -const internTwo = { - id: 1, +//* Write your intern objects here: +let mitzi = { id: 1, name: "Mitzi", email: "mmelloy0@psu.edu", gender: "F" }; +let kennan = { + id: 2, name: "Kennan", email: "kdiben1@tinypic.com", gender: "M" }; -const internThree = { - id: 2, +let keven = { + id: 3, name: "Keven", - email: "kmimmery2@wikimedia.org", + email: "kmummery2@wikimedia.org", gender: "M" }; - -const internFour = { - id: 3, +let gannie = { + id: 4, name: "Gannie", email: "gmartinson3@illinois.edu", gender: "M" }; -const internFive = { - id: 4, +let antonietta = { + 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(internOne.name); -// *Kennan's ID -console.log(internTwo.id); -// *Keven's email -console.log(internThree.email); -// *Gannie's name -console.log(internFour.name); -// *Antonietta's Gender -console.log(internFive.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 = "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=(3,4)"); - -//* === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js. +//* ==== 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()); +kennan.speak = function() { + return "Hello, my name is Kennan!"; +}; +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)); +antonietta.multiplyNums = function(num1, num2) { + return num1 * num2; +}; +console.log(antonietta.multiplyNums(3, 4)); // !==== Stretch Challenge: Nested Objects and the this keyword ==== @@ -81,8 +84,6 @@ console.log("antonietta.multiplyNums=(3,4)"); //! 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30 //! 4. Give each of the objects the ability to speak their names using the this keyword. -const parent = {}; - //* Log the parent object's name //* Log the child's age