From 7e391c80fea0fa9a0a7ffb93b9d32838ea206fe4 Mon Sep 17 00:00:00 2001 From: ignaciosm Date: Mon, 16 Sep 2019 14:23:06 -0500 Subject: [PATCH 1/9] challenges 1 and 2 --- assignments/objects.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/assignments/objects.js b/assignments/objects.js index 798d5e0cf..7815b3820 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -19,19 +19,63 @@ const example = { // Write your intern objects here: +const intern1 = { + id: 1, + name: "Mitzi", + email: "mmelloy0@psu.edu", + gender: "F", + +} + +const intern2 = { + id: 2, + name: "Kennan", + email: "kdiben1@psu.edu", + gender: "M", + +} + +const intern3 = { + id: 3, + name: "Keven", + email: "kmummery2@wikimedia.org", + gender: "M", + +} + +const intern4 = { + id: 4, + name: "Gannie", + email: "gmartinson3@illinois.edu", + gender: "M", + +} + +const intern5 = { + 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(intern1.name) // Kennan's ID +console.log(intern2.id) // Keven's email +console.log(intern3.email) // Gannie's name +console.log(intern4.name) // Antonietta's Gender +console.log(intern1.gender) // ==== Challenge 3: Object Methods ==== // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. From a480037894afe595a52a8e88940dd6641664728b Mon Sep 17 00:00:00 2001 From: ignaciosm Date: Mon, 16 Sep 2019 14:38:50 -0500 Subject: [PATCH 2/9] challenge 3 --- assignments/objects.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/assignments/objects.js b/assignments/objects.js index 7815b3820..62c2d3643 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -32,6 +32,9 @@ const intern2 = { name: "Kennan", email: "kdiben1@psu.edu", gender: "M", + speak: function() { + return "Hello, my name is " + this.name + "!"; + }, } @@ -56,6 +59,9 @@ const intern5 = { name: "Antonietta", email: "adaine5@samsung.com", gender: "F", + multiplyNums: function(num1,num2) { + return num1*num2; + } } @@ -80,9 +86,11 @@ console.log(intern1.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(intern2.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(intern5.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. From 848233bdffc4ab6c285244b7e00741db135d9c5e Mon Sep 17 00:00:00 2001 From: ignaciosm Date: Mon, 16 Sep 2019 15:28:12 -0500 Subject: [PATCH 3/9] arrays challenge 1 --- assignments/arrays.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 1dbf8bd35..72d269a4f 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -75,7 +75,13 @@ 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 *car year goes here* *car make goes here* *car model goes here*`); + +let result = []; +for (let i=0; i Date: Mon, 16 Sep 2019 15:35:45 -0500 Subject: [PATCH 4/9] arrays challenge 2 --- assignments/arrays.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 72d269a4f..c77cb40d9 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -85,8 +85,8 @@ console.log("Car 33 is a " + result[0].car_year, result[0].car_make, result[0].c // ==== 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(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 From ee8e966f91a651efb223f535cde6ed09a16372a1 Mon Sep 17 00:00:00 2001 From: ignaciosm Date: Mon, 16 Sep 2019 16:03:12 -0500 Subject: [PATCH 5/9] arrays challenge 3 --- assignments/arrays.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index c77cb40d9..838ff53f4 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -91,8 +91,12 @@ console.log(lastCar.car_make, lastCar.car_model); // ==== Challenge 3 ==== // The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console let carModels = []; -let carModelsSorted = []; -console.log(); +for (i = 0; i Date: Mon, 16 Sep 2019 16:04:35 -0500 Subject: [PATCH 6/9] arrays challenge 4 --- assignments/arrays.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 838ff53f4..b6851aaf9 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -101,7 +101,10 @@ 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 (i = 0; i Date: Mon, 16 Sep 2019 16:10:52 -0500 Subject: [PATCH 7/9] arrays challenge 5 --- assignments/arrays.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index b6851aaf9..df4aff8c5 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -109,7 +109,11 @@ 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 Date: Mon, 16 Sep 2019 16:15:53 -0500 Subject: [PATCH 8/9] arrays challenge 6 --- assignments/arrays.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index df4aff8c5..a69869433 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -118,4 +118,11 @@ 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 Date: Mon, 16 Sep 2019 16:29:12 -0500 Subject: [PATCH 9/9] add stretch goals --- assignments/objects.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/assignments/objects.js b/assignments/objects.js index 62c2d3643..2fd61994f 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -101,16 +101,42 @@ console.log(intern5.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 = {} +const parent = { + name: 'Susan', + age: 70, + speak: function(key) { + return "My name is " + this.name; + }, + child: { + name: 'George', + age: 50, + speak: function() { + return "My name is " + this.name; + }, + grandchild: { + name: 'Sam', + age: 30, + speak: function() { + return "My name is " + this.name; + }, + } + } +} // Log the parent object's name +console.log(parent.name) // Log the child's age +console.log(parent.child.name + "'s age is " + parent.child.age) // Log the name and age of the grandchild +console.log(parent.child.grandchild.name + "'s age is " + 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())