From 0e25aa2bfbaea23e0b209ce40eff68fa8d6baeea Mon Sep 17 00:00:00 2001 From: Zolton Date: Mon, 6 May 2019 14:24:01 -0400 Subject: [PATCH 1/4] Initial push/pull --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 51a4693ff..24bc101a9 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ **Follow these steps to set up and work on your project:** -* [ ] Create a forked copy of this project. -* [ ] Add your project manager as collaborator on Github. -* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!). -* [ ] Create a new branch: git checkout -b ``. +* [x ] Create a forked copy of this project. +* [ x] Add your project manager as collaborator on Github. +* [x ] Clone your OWN version of the repository (Not Lambda's by mistake!). +* [x ] Create a new branch: git checkout -b ``. * [ ] Implement the project on your newly created `` branch, committing changes regularly. * [ ] Push commits: git push origin ``. From 1c8d04014cd09ab4a0056b1c448f036497d65d7d Mon Sep 17 00:00:00 2001 From: Zolton Date: Mon, 6 May 2019 15:35:37 -0400 Subject: [PATCH 2/4] Finished Objects + Stretch goal. Starting on Arrays --- README.md | 15 ++++-- assignments/objects.js | 104 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 110 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 24bc101a9..3f0a840f0 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ * [ x] Add your project manager as collaborator on Github. * [x ] Clone your OWN version of the repository (Not Lambda's by mistake!). * [x ] Create a new branch: git checkout -b ``. -* [ ] Implement the project on your newly created `` branch, committing changes regularly. -* [ ] Push commits: git push origin ``. +* [x ] Implement the project on your newly created `` branch, committing changes regularly. +* [ x] Push commits: git push origin ``. **Follow these steps for completing your project.** -* [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** -* [ ] Add your project manager as a reviewer on the pull-request -* [ ] Your project manager will count the project as complete by merging the branch back into master. +* [x ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** +* [ x] Add your project manager as a reviewer on the pull-request +* [ x] Your project manager will count the project as complete by merging the branch back into master. ## Assignment Description @@ -29,6 +29,8 @@ * Once you finish the exercises in each file, commit your code, and push it to your fork. +**** 1 ***** + ### Objects To better understand objects, you really just need to write more of them. The [objects.js](assignments/objects.js) file contains several challenges centered around a theme of interns starting at a new job. The Human Resources team needs information about the new hires. Use your new found object skills answer vital questions for HR. @@ -36,6 +38,7 @@ To better understand objects, you really just need to write more of them. The [o * Read the instructions found within the file carefully to finish the challenges * Don't work on stretch until you have completed all assignments +**** 2 ***** ### Arrays The [arrays.js](assignments/arrays.js) assignment takes us through a large data set of used cars. You have been asked to help a used car business with some customer requests based on their inventory. Use for loops and arrays to solve their problems. @@ -44,6 +47,8 @@ The [arrays.js](assignments/arrays.js) assignment takes us through a large data * Use any array method you see fit to solve the problem * Don't work on stretch until you have completed all assignments +**** 3 ***** + ### Arrow Function Syntax * [ ] Arrow Function Syntax - [Check out this awesome guide for ES6 arrow syntax](https://medium.freecodecamp.org/when-and-why-you-should-use-es6-arrow-functions-and-when-you-shouldnt-3d851d7f0b26). You will see more and more arrow functions as you progress deeper into JavaScript. Use the [function-conversion.js](assignments/function-conversion.js) file as a helper challenge to showcase some of the differences between ES5 and ES6 syntax. diff --git a/assignments/objects.js b/assignments/objects.js index 40baf8d36..cdccfca0b 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -1,7 +1,9 @@ // 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: +// 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 @@ -19,46 +21,140 @@ const example = { // Write your intern objects here: +const employee1 = { + "id": 1, + "name": "Mitzi", + "email": "mmelloy0@psu.edu", + "gender": "F" +} + +const employee2 = { + "id": 2, + name: "Kennan", + "email": "kdiben1@tinypic.com", + "gender": "M", + speak: function () { + return "Hello, my name is " + employee2.name + } +} + +const employee3 = { + "id": 3, + "name": "Keven", + "email": "kmummery2@wikimedia.org", + "gender": "M", +} + +const employee4 = { + "id": 4, + "name": "Gannie", + "email": "gmartinson3@illinois.edu", + "gender": "M", +} + +const employee5 = { + "id": 5, + "name": "Antonietta", + "email": "madaine5@samsung.com", + "gender": "F", + multiplyNums: function (num1, num2) { + return num1 * num2; + } +} + + // ==== 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(employee1.name); + + // Kennan's ID +console.log(employee2.id); + // Keven's email +console.log(employee3.email); + // Gannie's name +console.log(employee4.name); + // Antonietta's Gender +console.log(employee5.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(employee2.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)); +console.log(employee5.multiplyNums(3,4)) + // === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge // ==== 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 +// 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 = { + name: "Susan", + age: 70, + speak: function () { + return "Hello, my name is " + this.name + }, + child: { + name: "George", + age: 50, + speak: function () { + return "Hello, my name is " + this.name + } + , + grandchild: { + name: "Sam", + age: 30, + speak: function () { + return "Hello, my name is " + this.name + } + } + } + } + // Log the parent object's name +console.log(parent.name); + // Log the child's age +console.log(parent.child.age); + // Log the name and age of the grandchild +console.log(parent.child.grandchild.name + parent.child.grandchild.age); + // Have the parent speak +console.log(parent.speak()); + // Have the child speak +console.log(parent.child.speak()); + // Have the grandchild speak + +console.log(parent.child.grandchild.speak()); From 6e5852bac434ed98928f2d676f5cf8f8fb352e9d Mon Sep 17 00:00:00 2001 From: Zolton Date: Mon, 6 May 2019 17:24:46 -0400 Subject: [PATCH 3/4] Done with today's relevant material. Not going to finish array.js as it's clearly a mistake to include --- assignments/arrays.js | 65 +++++++++++++++++++++++------- assignments/function-conversion.js | 36 +++++++++++++++-- assignments/objects.js | 4 +- 3 files changed, 85 insertions(+), 20 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 0b5ecad74..a1af7143a 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -1,8 +1,11 @@ -// 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}, +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}, @@ -51,7 +54,8 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year" {"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}]; +{"id":50,"car_make":"Lincoln","car_model":"Town Car","car_year":1999} +]; // Example for loop: @@ -62,31 +66,62 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year" // } // ==== 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*` ); +// 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_model + " made by " + inventory[32].car_make + " and the year is " + inventory[32].car_year); + + +//console.log("Car 33 is a" inventory[32] "*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(); +// 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.length - 1; +console.log(inventory[lastCar]); // ==== 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 = []; -console.log(); +// 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.sort(function(a, b){ + + var x = a.car_model.toLowerCase(); + var y = b.car_model.toLowerCase(); + if (x < y) {return -1;} + if (x > y) {return 1;} + return 0; + }); + +console.log(carModels); + + +// I'm done. This exercise is patently absurd, beyond the scope of today's lesson, as well as +// beyond the scope of the entire week. Challenge 2 was as far as I got on my own before +// having to google for formula's I don't understand in the least. Challenge 3 isn't my work, it's +// googling for someone elses work that I don't comprehend. +// It's obviously an oversight to include it, or at +// the very least, it should be labeled as an extreme stretch goal. Either way, +// it's not relevant to today's lesson. I'm incredibly angry that I wasted an hour on it before +// realizing this. + // ==== 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 = []; 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. +// 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. +// 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(); diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 55f57ef62..0a71d996a 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -5,26 +5,56 @@ // }; // myFunction(); +let myFunction = () => { + console.log("Function was invoked!"); +} +myFunction(); + // let anotherFunction = function (param) { // return param; // }; // anotherFunction("Example"); +let anotherFunction = (param) => { + return param; +} + +console.log(anotherFunction("example")); + // let add = function (param1, param2) { // return param1 + param2; // }; // add(1,2); +let add = (param1, param2) => { + return param1 + param2; +} + +console.log(add(1,2)); + // let subtract = function (param1, param2) { // return param1 - param2; // }; // subtract(1,2); +let subtract = (param1, param2) => { + return param1 - param2; +} + +console.log(subtract(1,2)); + // Stretch -// exampleArray = [1,2,3,4]; -// const triple = exampleArray.map(function (num) { +exampleArray = [1,2,3,4]; +// const triple = exampleArray.map(function (num) { num * 3 } ) + // return num * 3; + // }); -// console.log(triple); \ No newline at end of file + +// console.log(triple); + +let triple = exampleArray.map((num) => {return num * 3;}); + +console.log(triple); diff --git a/assignments/objects.js b/assignments/objects.js index cdccfca0b..1732ffd13 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -30,11 +30,11 @@ const employee1 = { const employee2 = { "id": 2, - name: "Kennan", + "name": "Kennan", "email": "kdiben1@tinypic.com", "gender": "M", speak: function () { - return "Hello, my name is " + employee2.name + return "Hello, my name is " + employee2["name"] } } From 5b1e94cd2295bd186bc2a462bdb7835146fd703a Mon Sep 17 00:00:00 2001 From: Zolton Date: Mon, 6 May 2019 21:08:54 -0400 Subject: [PATCH 4/4] Spent 3 hours banging my head against a wall & cursing the training kit. Half an hour of the zoom session and explaining how to use a for-loop, and I knocked out challenges 3, 4, 5, and 6 in less than 30 minutes --- assignments/arrays.js | 55 +++++++++++++++++++++++++++--------------- assignments/index.html | 3 ++- assignments/objects.js | 2 +- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index a1af7143a..6813997d9 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -79,51 +79,66 @@ console.log("Car 33 is a " + inventory[32].car_model + " made by " + inventory[3 // ==== 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.length - 1; console.log(inventory[lastCar]); // ==== 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.sort(function(a, b){ - - var x = a.car_model.toLowerCase(); - var y = b.car_model.toLowerCase(); - if (x < y) {return -1;} - if (x > y) {return 1;} - return 0; - }); -console.log(carModels); +let newArray = [] +for (let i = 0; i < inventory.length; i++) { + newArray.push(inventory[i].car_model) +} -// I'm done. This exercise is patently absurd, beyond the scope of today's lesson, as well as -// beyond the scope of the entire week. Challenge 2 was as far as I got on my own before -// having to google for formula's I don't understand in the least. Challenge 3 isn't my work, it's -// googling for someone elses work that I don't comprehend. -// It's obviously an oversight to include it, or at -// the very least, it should be labeled as an extreme stretch goal. Either way, -// it's not relevant to today's lesson. I'm incredibly angry that I wasted an hour on it before -// realizing this. +console.log(newArray.sort()); // ==== 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(); + +for (let i = 0; i < inventory.length; i++) { + carYears.push(inventory[i].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 = []; -console.log(); +console.log(carYears[5]) + +for (let i = 0; i < carYears.length; i++) { + if (carYears[i] < 2000) { + oldCars.push(carYears[i]) + } +} + +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(); +for (let i = 0; i < inventory.length; i++) + + if (inventory[i].car_make === "BMW" || inventory[i].car_make === "Audi") + + BMWAndAudi.push(inventory[i]) + + console.log (BMWAndAudi.length) +console.log(BMWAndAudi); +let myJSON = JSON.stringify(BMWAndAudi); +console.log(myJSON); \ No newline at end of file diff --git a/assignments/index.html b/assignments/index.html index 20a87acfa..a11729c63 100644 --- a/assignments/index.html +++ b/assignments/index.html @@ -8,8 +8,9 @@ JS I - + + diff --git a/assignments/objects.js b/assignments/objects.js index 1732ffd13..d23054207 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -69,7 +69,7 @@ const employee5 = { // Mitzi's name -console.log(employee1.name); +console.log(employee1["name"]); // Kennan's ID