From f9eb18bc152030981e661e6b4db43ca9b77cedbb Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 13:31:34 +0200 Subject: [PATCH 1/8] initial commit --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 23108974b..8cad262c1 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,6 @@ The [arrays.js](assignments/arrays.js) assignment takes us through a large data - Move on to tomorrow's content and start studying callbacks, write a few of your own to get the hang of it. - Look at array methods like .map(), .reduce(), .filter(). use them on the data in the arrays assignment to accomplish the same things you did with the ES5 for loop. + + +initial commit \ No newline at end of file From e8eff232b6d82271d0f45830940df670d3140832 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 14:37:28 +0200 Subject: [PATCH 2/8] finished object ass,array up untilchallenge3 --- assignments/arrays.js | 6 ++--- assignments/objects.js | 56 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 1dbf8bd35..055540bee 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -75,12 +75,12 @@ 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 ${[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. -let lastCar = 0; -console.log(); +let lastCar = 0 +console.log(inventory[49]["car_make"],inventory[49]["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 diff --git a/assignments/objects.js b/assignments/objects.js index 798d5e0cf..3f55ab47c 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -20,26 +20,74 @@ 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", + speaks: "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: "adaine5@samsung.com", + gender: "F", + multiplyNums: function (numa,numb){ + return numa*numb + } +} + + // ==== 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 +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.speaks) // 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 89ef2fcbcd1a1bacccbd63db7d83c9d80bf78b3e Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 15:57:52 +0200 Subject: [PATCH 3/8] writting the first part of challenge 3 --- assignments/arrays.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 055540bee..f06aea727 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -84,9 +84,18 @@ console.log(inventory[49]["car_make"],inventory[49]["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 = []; -let carModelsSorted = []; -console.log(); +let carModels =[] ; + + for (let i = 0; i < inventory.length; i++){ + let carModels = inventory[i].car_model.push; + + } + +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. From 1f109a6b0219f75e81c01b53699baa199796887e Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 19:57:41 +0200 Subject: [PATCH 4/8] finished up to challenge 5 --- assignments/arrays.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index f06aea727..3eb227046 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -87,10 +87,12 @@ console.log(inventory[49]["car_make"],inventory[49]["car_model"]); let carModels =[] ; for (let i = 0; i < inventory.length; i++){ - let carModels = inventory[i].car_model.push; + var theModels =inventory[i].car_model; + carModels.push(theModels); } + let carModelsSorted = carModels.sort(); @@ -100,14 +102,34 @@ 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 = []; -console.log(); + +for (let i = 0 ; i < inventory.length; i++){ + var theYears = inventory[i].car_year; + carYears.push(theYears); + +} +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(); + + +for (let i = 0 ; i < inventory.length; i++){ + if (inventory[i].car_year < 2000){ +var oldOld = inventory[i].car_year; +oldCars.push(oldOld); + } +} + +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(); From e46e6816f5c1750ca03054033e978d4b9f5bc4e7 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 20:21:44 +0200 Subject: [PATCH 5/8] finished challenge6 --- assignments/arrays.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 3eb227046..5ae4b0428 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -117,19 +117,23 @@ let oldCars = []; for (let i = 0 ; i < inventory.length; i++){ if (inventory[i].car_year < 2000){ -var oldOld = inventory[i].car_year; -oldCars.push(oldOld); + +oldCars.push(inventory[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 = []; +for (let i = 0 ; i < inventory.length; i++){ + if (inventory[i].car_make === "Audi" || + inventory[i].car_make === "BMW") { + BMWAndAudi.push(inventory[i]); + } + } + - - -console.log(); +console.log(BMWAndAudi); From 80825a59148a4f697fb1c2046738ede4395fd025 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 21:40:48 +0200 Subject: [PATCH 6/8] challenge6 completely out the park,back on stretch now --- assignments/arrays.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 5ae4b0428..2b64f7774 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -136,4 +136,4 @@ for (let i = 0 ; i < inventory.length; i++){ } -console.log(BMWAndAudi); +console.log(JSON.stringify(BMWAndAudi)); From b34850105a90dd39dc6fb518d29fcb7cd575b8fd Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 22:54:15 +0200 Subject: [PATCH 7/8] stretch completed --- assignments/objects.js | 49 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/assignments/objects.js b/assignments/objects.js index 3f55ab47c..a56ac632e 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -97,16 +97,53 @@ 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 +const parent = { +name: "Susan" , +age: 70, +speaks: "My name is ", +speakUp: function() { + console.log(`${this.speaks} ${this.name}`); +}, + child: { + name: "George", + age: 50, + speaks: "My name is ", + speakUp: function() { + console.log(`${this.speaks} ${this.name}`); + }, + grandchild: { + name: "Sam", + age: 30, + speaks: "My name is ", + speakUp: function() { + console.log(`${this.speaks} ${this.name}`); + }, + } +} +}; + -// Log the name and age of the grandchild + -// Have the parent speak +parent.speakUp(); +parent.child.speakUp(); +parent.child.grandchild.speakUp(); +// 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(this.speaks+this.name) // Have the child speak - +console.log (`${parent.child.speaks+parent.child.name} !`) // Have the grandchild speak +console.log(`${parent.child.grandchild.speaks+parent.child.grandchild.name}`) + +function speakUp() { + console.log(this.name); +} From 9171f81b6053e909fbfe5827fc9c10fb73d18e8a Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:24:12 +0200 Subject: [PATCH 8/8] mvp done --- assignments/arrays.js | 65 +++++++----- assignments/function-conversion.js | 16 +++ assignments/objects.js | 158 +++++++++++------------------ 3 files changed, 116 insertions(+), 123 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 2b64f7774..8a6139ec9 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -75,65 +75,80 @@ 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 ${[inventory[32]["car_year"],inventory[32]["car_make"],inventory[32]["car_model"]]}`); +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. -let lastCar = 0 -console.log(inventory[49]["car_make"],inventory[49]["car_model"]); +let lastCar = inventory[inventory.length-1]; + + +console.log(`Last car on the inventory, Make: ${lastCar.car_make} , Model: ${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 =[] ; +let carModels = []; - for (let i = 0; i < inventory.length; i++){ - var theModels =inventory[i].car_model; - carModels.push(theModels); - - } +for (let i = 0; i < inventory.length; i++){ + // Execute something here + carModels.push(inventory[i].car_model) +} -let carModelsSorted = carModels.sort(); +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 = []; -for (let i = 0 ; i < inventory.length; i++){ - var theYears = inventory[i].car_year; - carYears.push(theYears); - +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 = []; +for ( let i = 0 ; i < inventory.length; i++) { -for (let i = 0 ; i < inventory.length; i++){ - if (inventory[i].car_year < 2000){ + if (inventory[i].car_year < 2000 ) { -oldCars.push(inventory[i]); + oldCars.push(inventory[i].car_year) } + } 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 = []; -for (let i = 0 ; i < inventory.length; i++){ - if (inventory[i].car_make === "Audi" || - inventory[i].car_make === "BMW") { - BMWAndAudi.push(inventory[i]); +for (let i =0; i < inventory.length; i++ ) { + + if ( inventory[i].car_make.includes("BMW") || inventory[i].car_make.includes("Audi")) { + +BMWAndAudi.push(inventory[i]) } - } - +} + +var myCoolCars= JSON.stringify(BMWAndAudi); + + -console.log(JSON.stringify(BMWAndAudi)); +console.log(myCoolCars); diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 55f57ef62..45dc2e46d 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -5,21 +5,37 @@ // }; // myFunction(); +const myFunction = () => console.log("Function was invoked!"); + +myFunction(); + // let anotherFunction = function (param) { // return param; // }; // anotherFunction("Example"); + +const anotherFunction = (param) => param ; + +anotherFunction("hey"); + // let add = function (param1, param2) { // return param1 + param2; // }; // add(1,2); +const add = (param1, param2) => param1 + param2; + +add(1,2); + // let subtract = function (param1, param2) { // return param1 - param2; // }; // subtract(1,2); +const subtract = (param1, param2) => param1 - param2; + +console.logsubtract(1,2); // Stretch diff --git a/assignments/objects.js b/assignments/objects.js index a56ac632e..7a734e371 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -1,6 +1,6 @@ // Let's get some practice writing a few objects for a new group of interns at a small business. -// ==== Challenge 1: Writing Objects ==== +// ==== 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 @@ -14,136 +14,98 @@ const example = { id: 0, name: "Example", email: "examples@you.edu", - gender: "F", -} - -// Write your intern objects here: - - -var mitzi = { - id: 1, - name: "mitzi", - email: "mmelloy0@psu.edu", gender: "F" +}; -} +// Write your intern objects here: -var kennan = { - id: 2, - name: "kennan", +const mit = { + id: 6, + name: "Mitzi", + sex: "F", + email: "mmelloy0@psu.edu" +}; +const ken = { + id: 44, + name: "Kennan", + sex: "M", email: "kdiben1@tinypic.com", - gender: "M", - speaks: "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, + speak: (person)=> `Hello,my name is ${person.name}` +}; +const kev = { + id: 2, + name: "Keven", + sex: "M", + email: "kmummery2@wikimedia.org" +}; +const anto = { + id:55, name: "Antonietta", + sex: "F", email: "adaine5@samsung.com", - gender: "F", - multiplyNums: function (numa,numb){ - return numa*numb - } -} + multiplyNums: (a,b) => a*b +}; +const g = { + id:65, + name: "Gannie", + sex: "M", + email: "gmartinson3@illinois.edu" +}; + -// ==== Challenge 2: Reading Object Data ==== +// ==== 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) +console.log(mit.name); + // Kennan's ID -console.log(kennan.id) +console.log(ken.id); // Keven's email -console.log(keven.email) + +console.log(kev.email); // Gannie's name -console.log(gannie.name) + +console.log(g.name); // Antonietta's Gender -console.log(antonietta.gender) -// ==== Challenge 3: Object Methods ==== +console.log(anto.sex); + +// ==== 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.speaks) +console.log(ken.speak(ken)); + + + + // 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)) + + +console.log(anto.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 ==== +// ==== 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. - - -const parent = { -name: "Susan" , -age: 70, -speaks: "My name is ", -speakUp: function() { - console.log(`${this.speaks} ${this.name}`); -}, - child: { - name: "George", - age: 50, - speaks: "My name is ", - speakUp: function() { - console.log(`${this.speaks} ${this.name}`); - }, - grandchild: { - name: "Sam", - age: 30, - speaks: "My name is ", - speakUp: function() { - console.log(`${this.speaks} ${this.name}`); - }, - } -} -}; - - - - -parent.speakUp(); -parent.child.speakUp(); -parent.child.grandchild.speakUp(); +const parent = {}; // 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(this.speaks+this.name) + // Have the child speak -console.log (`${parent.child.speaks+parent.child.name} !`) -// Have the grandchild speak -console.log(`${parent.child.grandchild.speaks+parent.child.grandchild.name}`) -function speakUp() { - console.log(this.name); -} +// Have the grandchild speak