From 3f0c69f424824630c8abeaee57b58e338adbdfa3 Mon Sep 17 00:00:00 2001 From: Jojo Zhang Date: Mon, 22 Jul 2019 18:20:50 -0400 Subject: [PATCH 1/3] finish MVP --- assignments/arrays.js | 43 +++++++++++++++++++++------ assignments/objects.js | 66 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 93 insertions(+), 16 deletions(-) diff --git a/assignments/arrays.js b/assignments/arrays.js index 0b5ecad74..ea4bace8d 100644 --- a/assignments/arrays.js +++ b/assignments/arrays.js @@ -63,32 +63,57 @@ 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*` ); +function search(){ +for (let i=0; i < inventory.length; i++) { + if (inventory[i].id === 33) { + return inventory[i].car_year + " " + inventory[i].car_make + " " + inventory[i].car_model + } +} +} +console.log("Car 33 is a " + search()); // ==== 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 -let carModels = []; -console.log(); +let carModels = inventory.map ( + function(list){ + return list.car_model; + } +) +console.log(carModels.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(); +let carYears = inventory.map( + function(years){ + return years.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 Date: Mon, 22 Jul 2019 18:51:51 -0400 Subject: [PATCH 2/3] finish stretch goals. --- .vscode/launch.json | 14 ++++++++++++++ assignments/objects.js | 16 ++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..a053d2340 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/assignments/objects.js b/assignments/objects.js index 3373ec20a..f12700bca 100644 --- a/assignments/objects.js +++ b/assignments/objects.js @@ -93,24 +93,28 @@ console.log(Antonietta.multiplyNums(3,4)); const parent = { name: "Susan", age: 70, + speak: function(){console.log("Hello, my name is " + this.name)}, child: { name: "George", age: 50, + speak: function(){console.log("Hello, my name is " + this.name)}, grandchild: { name: "Sam", - age: 30 + age: 30, + speak: function(){console.log("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.name) // 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()) \ No newline at end of file From b1564e320936474be1569a58f5ce6c68a1fc27e8 Mon Sep 17 00:00:00 2001 From: Jojo Zhang Date: Mon, 22 Jul 2019 19:07:11 -0400 Subject: [PATCH 3/3] add function-conversion.js changes --- assignments/function-conversion.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 55f57ef62..1be083829 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -5,21 +5,38 @@ // }; // myFunction(); +let myFunction = ()=> +console.log("Function was invoked!"); + +myFunction(); + // let anotherFunction = function (param) { // return param; // }; // anotherFunction("Example"); +let anotherFunction = param => param; + +anotherFunction("Example"); + // let add = function (param1, param2) { // return param1 + param2; // }; // add(1,2); +let add = (param1, param2) => param1 + param2; + +add(1,2); + // let subtract = function (param1, param2) { // return param1 - param2; // }; // subtract(1,2); +let subtract = (param1, param2) => param1 - param2; + +subtract(1,2); + // Stretch @@ -27,4 +44,8 @@ // 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) \ No newline at end of file