From f9eb18bc152030981e661e6b4db43ca9b77cedbb Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 19 Aug 2019 13:31:34 +0200 Subject: [PATCH 01/14] 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 02/14] 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 03/14] 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 04/14] 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 05/14] 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 06/14] 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 07/14] 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 df7977f4258b10a4d0827197da6b261b85d9b556 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Wed, 28 Aug 2019 15:01:05 +0200 Subject: [PATCH 08/14] done,clean --- assignments/arrays.js | 87 ++++++++++++++++++++++++--- assignments/function-conversion.js | 35 ++++++++++- assignments/objects.js | 96 +++++++++++++++++++++++++++++- 3 files changed, 208 insertions(+), 10 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 1dbf8bd35..e84318b86 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -75,30 +75,103 @@ 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*`); + +for (let i = 0; i < inventory.length ; i++){ + + if ( inventory[i].id === 33){ + +console.log(`Car 33 is a ${inventory[i].car_year} , ${inventory[i].car_make} , ${inventory[i].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(); + +for ( let i = 0; i < inventory.length; i++){ + if ( inventory[i] === inventory[ inventory.length-1]){ + console.log(`${inventory[i].car_make} ${inventory[i].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(); + +for ( let i = 0; i < inventory.length; i++){ + carModels.push(inventory[i].car_model) +} + + 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 = []; -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(); + +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 === "Audi" || inventory[i].car_make === " BMW") { + BMWAndAudi.push(inventory[i]) + + } +} + + + +console.log(BMWAndAudi); diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 55f57ef62..7555069a7 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -5,26 +5,57 @@ // }; // myFunction(); +let myFunction = () => console.log("Function was invoked!"); + +myFunction(); + + + + // let anotherFunction = function (param) { // return param; // }; // anotherFunction("Example"); + +let anotherFunction = (param) => param; + +console.log(anotherFunction("Example")); + + // let add = function (param1, param2) { // return param1 + param2; // }; // add(1,2); + +let add = (param1, param2) => param1 + param2; + +console.log(add(1,2)); + + // let subtract = function (param1, param2) { // return param1 - param2; // }; // subtract(1,2); +let subtract = ( param1, param2) => param1 - param2; + +console.log(subtract(1,2)); + // Stretch -// exampleArray = [1,2,3,4]; +// // const triple = exampleArray.map(function (num) { // return num * 3; // }); -// console.log(triple); \ No newline at end of file +// console.log(triple); + +exampleArray = [1,2,3,4]; + +const triple = exampleArray.map(num => num * 3) + +console.log(triple); + + diff --git a/assignments/objects.js b/assignments/objects.js index 798d5e0cf..1e63e2181 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -19,26 +19,79 @@ const example = { // Write your intern objects here: +var mitzi = { + id: 1, + name: "mitzi", + email: "mmelloy0@psu.edu", + gender: "F" + +} + + + + +const kennan = { + id: 2, + name: "kennan", + email: "kdiben1@tinypic.com", + gender: "M", + speaks: "Hello,my name is Kennan!" +} + +const keven = { + id: 3, + name: "keven", + email: "kmummery2@wikimedia.org", + gender: "M" + +} + +const gannie = { + id: 4, + name: "Gannie", + email: "gmartinson3@illinois.edu", + gender: "M" + +} + + +const 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 +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. @@ -49,16 +102,57 @@ const example = { // 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, + 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(); // 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 037a73f8e976d5ea6c6f45d609abdd3ba2f7e8d4 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Wed, 28 Aug 2019 15:15:48 +0200 Subject: [PATCH 09/14] fixed an undefined problem for a function --- assignments/objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignments/objects.js b/assignments/objects.js index 1e63e2181..5f08bed4e 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -144,7 +144,7 @@ console.log(parent.child.age) console.log(parent.child.grandchild.name,parent.child.grandchild.age) // Have the parent speak -console.log(this.speaks+this.name) +console.log(`${parent.speaks} ${parent.name}`) // Have the child speak console.log (`${parent.child.speaks+parent.child.name} !`) From 9171f81b6053e909fbfe5827fc9c10fb73d18e8a Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:24:12 +0200 Subject: [PATCH 10/14] 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 From ee498f06dc1a84d5255e59792b441d40fdcb7a61 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:29:44 +0200 Subject: [PATCH 11/14] MVP --- assignments/arrays.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assignments/arrays.js b/assignments/arrays.js index 8a6139ec9..2bd78cef8 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -152,3 +152,6 @@ var myCoolCars= JSON.stringify(BMWAndAudi); console.log(myCoolCars); + + +//// From 8b7c06283ae1d40bb71fabaf9b7ec855fb443686 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:34:29 +0200 Subject: [PATCH 12/14] some refactoring --- assignments/arrays.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 2bd78cef8..671c4a992 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -154,4 +154,3 @@ var myCoolCars= JSON.stringify(BMWAndAudi); console.log(myCoolCars); -//// From c0968678be9ed73d05cc6bc0868d32271eef35f8 Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:35:56 +0200 Subject: [PATCH 13/14] stretches --- assignments/objects.js | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/assignments/objects.js b/assignments/objects.js index 7a734e371..84cba8604 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -109,3 +109,54 @@ const parent = {}; // Have the child speak // Have the grandchild speak + + +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(); + + // 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); + } + \ No newline at end of file From 9d0e6d47f2f9df06dd0ab65e441752ad2c686b8c Mon Sep 17 00:00:00 2001 From: AbdelIdir Date: Mon, 14 Oct 2019 17:45:06 +0200 Subject: [PATCH 14/14] some refactoring and cleaned code --- assignments/arrays.js | 70 ++++++++++------------ assignments/function-conversion.js | 19 +++--- assignments/objects.js | 96 +++++++++++++----------------- 3 files changed, 85 insertions(+), 100 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 671c4a992..0f3679ead 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 }, @@ -75,29 +85,27 @@ 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 = inventory[inventory.length-1]; - - -console.log(`Last car on the inventory, Make: ${lastCar.car_make} , Model: ${lastCar.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 = []; -for (let i = 0; i < inventory.length; i++){ +for (let i = 0; i < inventory.length; i++) { // Execute something here - carModels.push(inventory[i].car_model) - + carModels.push(inventory[i].car_model); } - - let carModelsSorted = [carModels.sort()]; console.log(carModelsSorted); @@ -106,51 +114,39 @@ console.log(carModelsSorted); let carYears = []; -for ( let i = 0 ; i < inventory.length ; i++ ) { - - carYears.push(inventory[i].car_year) +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++) { - - if (inventory[i].car_year < 2000 ) { - - oldCars.push(inventory[i].car_year) +for (let i = 0; i < inventory.length; i++) { + if (inventory[i].car_year < 2000) { + 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.includes("BMW") || inventory[i].car_make.includes("Audi")) { - -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); - - +var myCoolCars = JSON.stringify(BMWAndAudi); console.log(myCoolCars); - - diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 45dc2e46d..6befcc42a 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -5,7 +5,7 @@ // }; // myFunction(); -const myFunction = () => console.log("Function was invoked!"); +const myFunction = () => console.log("Function was invoked!"); myFunction(); @@ -14,8 +14,7 @@ myFunction(); // }; // anotherFunction("Example"); - -const anotherFunction = (param) => param ; +const anotherFunction = param => param; anotherFunction("hey"); @@ -24,9 +23,9 @@ anotherFunction("hey"); // }; // add(1,2); -const add = (param1, param2) => param1 + param2; +const add = (param1, param2) => param1 + param2; -add(1,2); +add(1, 2); // let subtract = function (param1, param2) { // return param1 - param2; @@ -35,12 +34,16 @@ add(1,2); const subtract = (param1, param2) => param1 - param2; -console.logsubtract(1,2); +console.log(subtract(1, 2)); // Stretch -// exampleArray = [1,2,3,4]; +exampleArray = [1, 2, 3, 4]; // const triple = exampleArray.map(function (num) { // return num * 3; // }); -// console.log(triple); \ No newline at end of file +// console.log(triple); + +const triple = exampleArray.map(num => num * 3); + +console.log(triple); diff --git a/assignments/objects.js b/assignments/objects.js index 84cba8604..9aef3478c 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -30,7 +30,7 @@ const ken = { name: "Kennan", sex: "M", email: "kdiben1@tinypic.com", - speak: (person)=> `Hello,my name is ${person.name}` + speak: person => `Hello,my name is ${person.name}` }; const kev = { id: 2, @@ -39,21 +39,19 @@ const kev = { email: "kmummery2@wikimedia.org" }; const anto = { - id:55, + id: 55, name: "Antonietta", sex: "F", email: "adaine5@samsung.com", - multiplyNums: (a,b) => a*b + multiplyNums: (a, b) => a * b }; const g = { - id:65, + id: 65, name: "Gannie", sex: "M", email: "gmartinson3@illinois.edu" }; - - // ==== Challenge 2: Reading Object Data ==== // Once your objects are created, log out the following requests from HR into the console: @@ -61,7 +59,6 @@ const g = { console.log(mit.name); - // Kennan's ID console.log(ken.id); // Keven's email @@ -79,13 +76,9 @@ console.log(anto.sex); // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. 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(anto.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. @@ -96,8 +89,6 @@ console.log(anto.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 @@ -110,53 +101,48 @@ const parent = {}; // Have the grandchild speak - const parent = { - name: "Susan" , - age: 70, + 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 ", + 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}`); - }, - 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(); - - // 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); - } - \ No newline at end of file +}; + +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); +}