From c948982ec519be82eaabd9a33124245338ca28aa Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 16:28:53 -0400 Subject: [PATCH 01/12] Completed Task 1 --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3a474a3f4..26a2b36be 100644 --- a/index.js +++ b/index.js @@ -36,10 +36,14 @@ function addNumbers(num1, num2) { * the returned value should look like: 'Goodbye, Andy. Have a great day.' * */ -function sayGoodbye(/* code here */) { +function sayGoodbye(name) { /* code here */ + console.log(`Goodbye, ${name}. Have a great day.`) + } +sayGoodbye("Cameron") + /** * ### Challenge `temperatureCtoF` * From 80a7e9c398a7345145b67c0a84109bb52813641c Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 16:33:52 -0400 Subject: [PATCH 02/12] Completed Task 2 --- index.js | 182 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 128 insertions(+), 54 deletions(-) diff --git a/index.js b/index.js index 26a2b36be..b14ccb045 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ * the returned value should be 8. * * NOTE: This example has been completed for you. -*/ + */ function addNumbers(num1, num2) { return num1 + num2; } @@ -35,11 +35,10 @@ function addNumbers(num1, num2) { * passing 'Andy' as the argument, * the returned value should look like: 'Goodbye, Andy. Have a great day.' * -*/ + */ function sayGoodbye(name) { /* code here */ - console.log(`Goodbye, ${name}. Have a great day.`) - + console.log(`Goodbye, ${name}. Have a great day.`) } sayGoodbye("Cameron") @@ -57,11 +56,18 @@ sayGoodbye("Cameron") * * Hint 1: The formula for converting celsius to fahrenheit is t*9/5 + 32 where t is the temperature in celsius. * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. -*/ -function temperatureCtoF(/* code here */) { + */ +function temperatureCtoF(celsius) { /* code here */ + + let convert = celsius * 9 / 5 + 32; + return Math.round(convert); + } +console.log(temperatureCtoF(24)) + + /** * ### Challenge `temperatureInF` * @@ -78,8 +84,8 @@ function temperatureCtoF(/* code here */) { * the returned value should be: '75F' * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. -*/ -function temperatureInF(/* code here */) { + */ +function temperatureInF( /* code here */ ) { /* code here */ } @@ -99,8 +105,8 @@ function temperatureInF(/* code here */) { * name: "Leia", * email: "leia@leia.com", * } -*/ -function makePersonObject(/* code here */) { + */ +function makePersonObject( /* code here */ ) { /* code here */ } @@ -116,8 +122,8 @@ function makePersonObject(/* code here */) { * For example, if we invoke `getName` * passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument, * the returned value should look like `Hello, my name is Leia`. -*/ -function getName(/* code here */) { + */ +function getName( /* code here */ ) { /* code here */ } @@ -136,8 +142,8 @@ function getName(/* code here */) { * For example, if we invoke `appleIndex` * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. -*/ -function appleIndex(/* code here */) { + */ +function appleIndex( /* code here */ ) { /* code here */ } @@ -155,8 +161,8 @@ function appleIndex(/* code here */) { * For example, if we invoke `isItAnApple` * passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument, * the returned value should be: [ false, true, false, false, true, false ]. -*/ -function isItAnApple(/* code here */) { + */ +function isItAnApple( /* code here */ ) { /* code here */ } @@ -165,32 +171,101 @@ function isItAnApple(/* code here */) { // ⭐️ Example Test Data ⭐️ -var 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 }, - { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, - { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, - { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, - { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, - { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, - { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, - { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, - { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, - { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 }, - { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 } +var 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 + }, + { + id: 5, + car_make: "Mitsubishi", + car_model: "Galant", + car_year: 1990 + }, + { + id: 6, + car_make: "Honda", + car_model: "Accord", + car_year: 1995 + }, + { + id: 7, + car_make: "Smart", + car_model: "Fortwo", + car_year: 2009 + }, + { + id: 8, + car_make: "Audi", + car_model: "4000CS Quattro", + car_year: 1987 + }, + { + id: 9, + car_make: "Ford", + car_model: "Windstar", + car_year: 1996 + }, + { + id: 10, + car_make: "Mercedes-Benz", + car_model: "E-Class", + car_year: 2000 + }, + { + id: 11, + car_make: "Infiniti", + car_model: "G35", + car_year: 2004 + }, + { + id: 12, + car_make: "Lotus", + car_model: "Esprit", + car_year: 2004 + }, + { + id: 13, + car_make: "Chevrolet", + car_model: "Cavalier", + car_year: 1997 + }, + { + id: 14, + car_make: "Dodge", + car_model: "Ram Van 1500", + car_year: 1999 + } ] /** - * ### Example Array Challenge: - * - * @instructions - * get3rdCar() should return the string `The is a Land Rover Defender Ice Edition` - * - * - * NOTE: This example has been completed for you. -**/ + * ### Example Array Challenge: + * + * @instructions + * get3rdCar() should return the string `The is a Land Rover Defender Ice Edition` + * + * + * NOTE: This example has been completed for you. + **/ function get3rdCar(inventory) { const the3rd = inventory[2]; return `The is a ${the3rd.car_make} ${the3rd.car_model}` @@ -212,7 +287,7 @@ function get3rdCar(inventory) { * * For example, if getCarInfoByIndex is invoked with the inventory and the number 0, * it will return `This is a Lincoln Navigator`. -*/ + */ function getCarInfoByIndex(inventory, index) { /* code here */ } @@ -227,8 +302,8 @@ function getCarInfoByIndex(inventory, index) { * * For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js, * it will return `This is a Lincoln Town Car`. -*/ -function getLastCarInfo(/* code here */) { + */ +function getLastCarInfo( /* code here */ ) { /* code here */ } @@ -240,8 +315,8 @@ function getLastCarInfo(/* code here */) { * getModelYears takes a single argument: * (1) an array which is an inventory of cars like the one inside /data/inventory.js. * getModelYears returns an array containing all the 'car_year's in the inventory. -*/ -function getModelYears(/* code here */) { + */ +function getModelYears( /* code here */ ) { /* code here */ } @@ -258,8 +333,8 @@ function getModelYears(/* code here */) { * * For example, if getCarInfoById is invoked with the inventory and the number 1, * it will return `This is a Lincoln Navigator`. -*/ -function getCarInfoById(/* code here */) { + */ +function getCarInfoById( /* code here */ ) { /* code here */ } @@ -276,8 +351,8 @@ function getCarInfoById(/* code here */) { * getOlderCars returns an array containing all the cars * with a `car_year` which is at most the given desired max year, * in the same order as they appear in the original inventory. -*/ -function getOlderCars(/* code here */) { + */ +function getOlderCars( /* code here */ ) { /* code here */ } @@ -293,8 +368,8 @@ function getOlderCars(/* code here */) { * getGermanCars returns an array containing all the cars * made by either `Audi` or `Mercedes-Benz` or `Volkswagen` or `BMW`, * in the same order as they appear in the original inventory. -*/ -function getGermanCars(/* code here */) { + */ +function getGermanCars( /* code here */ ) { /* code here */ } @@ -310,8 +385,7 @@ function getGermanCars(/* code here */) { * it has a `drive` method that takes a distance as its argument, and * (1) causes the odometer in the object to be increased by the distance, * (2) returns the updated value of the `odometer`. -*/ -function carMaker(/* code here */) { + */ +function carMaker( /* code here */ ) { /* code here */ -} - +} \ No newline at end of file From e36cca8cb114eaf48d7bd19616b893972d87cd56 Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 17:14:13 -0400 Subject: [PATCH 03/12] Completed Task 3 --- index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b14ccb045..f93213c2b 100644 --- a/index.js +++ b/index.js @@ -85,10 +85,25 @@ console.log(temperatureCtoF(24)) * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF( /* code here */ ) { - /* code here */ +function temperatureInF(temperature,unit) { + + if(unit==="C"){ + function temperatureCtoF(C) { + const convert = C * 9 / 5 + 32; + return Math.round(convert); + } + console.log(temperatureCtoF(temperature,"C")+"C"); + } + + else if(unit==="F"){ + return temperature + "F" + + } } +console.log(temperatureInF(88,"C")); + + /** * ### Challenge `makePersonObject` From d4af4cb68bab891e0a197c07d8ac1282a4ff3b08 Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 17:25:49 -0400 Subject: [PATCH 04/12] Completed Task 4 --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f93213c2b..385428ddc 100644 --- a/index.js +++ b/index.js @@ -121,9 +121,13 @@ console.log(temperatureInF(88,"C")); * email: "leia@leia.com", * } */ -function makePersonObject( /* code here */ ) { +function makePersonObject(id,name,email ) { /* code here */ + const person= {id,name,email} + return person; } +console.log(makePersonObject(5,"Cameron","cameron@email.com")); + /** * ### Challenge `getName` From cda6f8fa1f9e366dc7a34cd218a3f4a88698bd89 Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 17:34:38 -0400 Subject: [PATCH 05/12] Completed Task 5 --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 385428ddc..afd6ea04f 100644 --- a/index.js +++ b/index.js @@ -142,10 +142,13 @@ console.log(makePersonObject(5,"Cameron","cameron@email.com")); * passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument, * the returned value should look like `Hello, my name is Leia`. */ -function getName( /* code here */ ) { - /* code here */ +function getName(name) { + name={id:1,name:"Cameron",email:"cameron@email.com"}; + return `Hello, my name is ${name.name}`; } +console.log(getName()) + /** * ### Challenge `appleIndex` From 7a7b718a0e7c165b012e4e082fc93a6d6710b5ce Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 18:49:59 -0400 Subject: [PATCH 06/12] Completed Task 6 --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index afd6ea04f..6322b60e9 100644 --- a/index.js +++ b/index.js @@ -165,10 +165,14 @@ console.log(getName()) * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex( /* code here */ ) { +function appleIndex( arr ) { /* code here */ + const fruits= [ 'orange', 'grape', 'apple', 'banana', 'mango' ]; + return fruits.indexOf(arr) } +console.log(appleIndex('apple')); + /** * ### Challenge `isItAnApple` * From 5cef4df9df3e727e786570fd5e93337f9dc73861 Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 21:57:10 -0400 Subject: [PATCH 07/12] Completed Task 7 --- index.js | 142 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 118 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index 6322b60e9..7c4c411da 100644 --- a/index.js +++ b/index.js @@ -85,23 +85,21 @@ console.log(temperatureCtoF(24)) * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(temperature,unit) { - - if(unit==="C"){ - function temperatureCtoF(C) { - const convert = C * 9 / 5 + 32; - return Math.round(convert); - } - console.log(temperatureCtoF(temperature,"C")+"C"); - } - - else if(unit==="F"){ - return temperature + "F" - +function temperatureInF(temperature, unit) { + + if (unit === "C") { + function temperatureCtoF(C) { + const convert = C * 9 / 5 + 32; + return Math.round(convert); } + console.log(temperatureCtoF(temperature, "C") + "C"); + } else if (unit === "F") { + return temperature + "F" + + } } -console.log(temperatureInF(88,"C")); +console.log(temperatureInF(88, "C")); @@ -121,12 +119,16 @@ console.log(temperatureInF(88,"C")); * email: "leia@leia.com", * } */ -function makePersonObject(id,name,email ) { +function makePersonObject(id, name, email) { /* code here */ - const person= {id,name,email} + const person = { + id, + name, + email + } return person; } -console.log(makePersonObject(5,"Cameron","cameron@email.com")); +console.log(makePersonObject(5, "Cameron", "cameron@email.com")); /** @@ -143,8 +145,12 @@ console.log(makePersonObject(5,"Cameron","cameron@email.com")); * the returned value should look like `Hello, my name is Leia`. */ function getName(name) { - name={id:1,name:"Cameron",email:"cameron@email.com"}; - return `Hello, my name is ${name.name}`; + name = { + id: 1, + name: "Cameron", + email: "cameron@email.com" + }; + return `Hello, my name is ${name.name}`; } console.log(getName()) @@ -165,9 +171,9 @@ console.log(getName()) * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex( arr ) { +function appleIndex(arr) { /* code here */ - const fruits= [ 'orange', 'grape', 'apple', 'banana', 'mango' ]; + const fruits = ['orange', 'grape', 'apple', 'banana', 'mango']; return fruits.indexOf(arr) } @@ -188,9 +194,27 @@ console.log(appleIndex('apple')); * passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument, * the returned value should be: [ false, true, false, false, true, false ]. */ -function isItAnApple( /* code here */ ) { +// +const fruits = ['orange', 'grape', 'apple', 'banana', 'mango']; + +function isItAnApple(arr) { /* code here */ + const newFruit = []; //New empty array created + for (let i = 0; i < arr.length; i++){ //iterate though fruits array + if (arr[i] === 'apple') { //condition for index of fruits array + + newFruit.push(true); //Push boolean true into newFruit array + } else { + newFruit.push(false); // else Push boolean false into newFruit array + } + } + + return newFruit; // return result } +console.log(isItAnApple(fruits)); + + + @@ -292,11 +316,12 @@ var inventory = [{ * * NOTE: This example has been completed for you. **/ -function get3rdCar(inventory) { +function get3rdCar(inv) { const the3rd = inventory[2]; return `The is a ${the3rd.car_make} ${the3rd.car_model}` } +console.log(get3rdCar(2)); // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 @@ -314,10 +339,79 @@ function get3rdCar(inventory) { * For example, if getCarInfoByIndex is invoked with the inventory and the number 0, * it will return `This is a Lincoln Navigator`. */ -function getCarInfoByIndex(inventory, index) { + + + +function getCarInfoByIndex(inv, index) { /* code here */ + +// 1st paramter must be inventory +// 2nd paramter must be arr=this.car_make + +const cars = inventory[inv] +const cars2 =inventory[index] + return `The is a ${cars.car_make} ${cars2.car_model}` + } +console.log(getCarInfoByIndex(0, 0)); + + + + +/*----------------------------------------------------------------*/ +const data=[ +{ 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 }, +{ id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, +{ id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, +{ id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, +{ id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, +{ id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, +{ id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, +{ id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, +{ id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, +{ 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: 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 }, +{ id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 }, +{ id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 }, +{ id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 }, +{ id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 }, +{ id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 }, +{ id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, +{ id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 }, +{ id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 }, +{ id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 }, +{ id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 }, +{ id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, +{ id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 }, +{ id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 }, +{ id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 }, +{ id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 }, +{ id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 }, +{ id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 }, +{ id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 }, +{ id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 }, +{ id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 }, +{ id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 }, +{ id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 }, +{ id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 }, +{ id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 }, +{ id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, +{ id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, +{ id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 }, +{ 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 } +] /** * ### Challenge `getLastCarInfo` * From 2a06707183bbb545007a9bf8eb3687eb8292f97b Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Thu, 14 May 2020 22:38:53 -0400 Subject: [PATCH 08/12] Completed Task 8 --- index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7c4c411da..a05518cd2 100644 --- a/index.js +++ b/index.js @@ -423,9 +423,12 @@ const data=[ * For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js, * it will return `This is a Lincoln Town Car`. */ -function getLastCarInfo( /* code here */ ) { +function getLastCarInfo(inv) { /* code here */ + + console.log(`This is a ${data[49].car_make},${data[49].car_model}`) } +getLastCarInfo() /** * ### Challenge `getModelYears` @@ -436,10 +439,23 @@ function getLastCarInfo( /* code here */ ) { * (1) an array which is an inventory of cars like the one inside /data/inventory.js. * getModelYears returns an array containing all the 'car_year's in the inventory. */ -function getModelYears( /* code here */ ) { + + +function getModelYears(inv) { /* code here */ + + const years=[]; + + for(let i=0; i Date: Thu, 14 May 2020 23:49:33 -0400 Subject: [PATCH 09/12] Completed MVP --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a05518cd2..bc67d018c 100644 --- a/index.js +++ b/index.js @@ -426,9 +426,11 @@ const data=[ function getLastCarInfo(inv) { /* code here */ - console.log(`This is a ${data[49].car_make},${data[49].car_model}`) + + console.log(`This is a ${data[inv.length-1].car_make},${data[inv.length-1].car_model}`) + } -getLastCarInfo() +getLastCarInfo(data) /** * ### Challenge `getModelYears` From 0be14dca91a7742ed859426e274c97848b795557 Mon Sep 17 00:00:00 2001 From: Cameron Lares Date: Fri, 15 May 2020 02:46:39 -0400 Subject: [PATCH 10/12] First Attempt at Stretch --- index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index bc67d018c..8a3338a9b 100644 --- a/index.js +++ b/index.js @@ -472,10 +472,17 @@ console.log(getModelYears(data)); * For example, if getCarInfoById is invoked with the inventory and the number 1, * it will return `This is a Lincoln Navigator`. */ -function getCarInfoById( /* code here */ ) { +function getCarInfoById(make,model) { /* code here */ + +const MAKE=Object.values(data)[make].car_make; +const MODEL= Object.values(data)[model].car_model; + +return `This is a ${MAKE} ${MODEL}` } +console.log(getCarInfoById(1,1)); + /** * ### Challenge `getOlderCars` * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER @@ -490,9 +497,17 @@ function getCarInfoById( /* code here */ ) { * with a `car_year` which is at most the given desired max year, * in the same order as they appear in the original inventory. */ -function getOlderCars( /* code here */ ) { - /* code here */ +function getOlderCars(cars,years ) { + + let newCars=[]; + for(let i=0; i Date: Fri, 15 May 2020 14:37:56 -0400 Subject: [PATCH 11/12] Formatted JS file --- index.js | 405 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 327 insertions(+), 78 deletions(-) diff --git a/index.js b/index.js index 8a3338a9b..48aaa8400 100644 --- a/index.js +++ b/index.js @@ -200,12 +200,12 @@ const fruits = ['orange', 'grape', 'apple', 'banana', 'mango']; function isItAnApple(arr) { /* code here */ const newFruit = []; //New empty array created - for (let i = 0; i < arr.length; i++){ //iterate though fruits array + for (let i = 0; i < arr.length; i++) { //iterate though fruits array if (arr[i] === 'apple') { //condition for index of fruits array - + newFruit.push(true); //Push boolean true into newFruit array } else { - newFruit.push(false); // else Push boolean false into newFruit array + newFruit.push(false); // else Push boolean false into newFruit array } } @@ -344,12 +344,12 @@ console.log(get3rdCar(2)); function getCarInfoByIndex(inv, index) { /* code here */ - -// 1st paramter must be inventory -// 2nd paramter must be arr=this.car_make -const cars = inventory[inv] -const cars2 =inventory[index] + // 1st paramter must be inventory + // 2nd paramter must be arr=this.car_make + + const cars = inventory[inv] + const cars2 = inventory[index] return `The is a ${cars.car_make} ${cars2.car_model}` } @@ -360,57 +360,306 @@ console.log(getCarInfoByIndex(0, 0)); /*----------------------------------------------------------------*/ -const data=[ -{ 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 }, -{ id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, -{ id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, -{ id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, -{ id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, -{ id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, -{ id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, -{ id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, -{ id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, -{ 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: 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 }, -{ id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 }, -{ id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 }, -{ id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 }, -{ id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 }, -{ id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 }, -{ id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, -{ id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 }, -{ id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 }, -{ id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 }, -{ id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 }, -{ id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, -{ id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 }, -{ id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 }, -{ id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 }, -{ id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 }, -{ id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 }, -{ id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 }, -{ id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 }, -{ id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 }, -{ id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 }, -{ id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 }, -{ id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 }, -{ id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 }, -{ id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 }, -{ id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, -{ id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, -{ id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 }, -{ 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 } +const data = [{ + 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 + }, + { + id: 5, + car_make: "Mitsubishi", + car_model: "Galant", + car_year: 1990 + }, + { + id: 6, + car_make: "Honda", + car_model: "Accord", + car_year: 1995 + }, + { + id: 7, + car_make: "Smart", + car_model: "Fortwo", + car_year: 2009 + }, + { + id: 8, + car_make: "Audi", + car_model: "4000CS Quattro", + car_year: 1987 + }, + { + id: 9, + car_make: "Ford", + car_model: "Windstar", + car_year: 1996 + }, + { + id: 10, + car_make: "Mercedes-Benz", + car_model: "E-Class", + car_year: 2000 + }, + { + id: 11, + car_make: "Infiniti", + car_model: "G35", + car_year: 2004 + }, + { + id: 12, + car_make: "Lotus", + car_model: "Esprit", + car_year: 2004 + }, + { + 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: 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 + }, + { + id: 20, + car_make: "Mazda", + car_model: "Familia", + car_year: 1985 + }, + { + id: 21, + car_make: "Chevrolet", + car_model: "Express 1500", + car_year: 2003 + }, + { + id: 22, + car_make: "Jeep", + car_model: "Wrangler", + car_year: 1997 + }, + { + id: 23, + car_make: "Eagle", + car_model: "Talon", + car_year: 1992 + }, + { + id: 24, + car_make: "Toyota", + car_model: "MR2", + car_year: 2003 + }, + { + id: 25, + car_make: "BMW", + car_model: "525", + car_year: 2005 + }, + { + id: 26, + car_make: "Cadillac", + car_model: "Escalade", + car_year: 2005 + }, + { + id: 27, + car_make: "Infiniti", + car_model: "Q", + car_year: 2000 + }, + { + id: 28, + car_make: "Suzuki", + car_model: "Aerio", + car_year: 2005 + }, + { + id: 29, + car_make: "Mercury", + car_model: "Topaz", + car_year: 1993 + }, + { + id: 30, + car_make: "BMW", + car_model: "6 Series", + car_year: 2010 + }, + { + id: 31, + car_make: "Pontiac", + car_model: "GTO", + car_year: 1964 + }, + { + id: 32, + car_make: "Dodge", + car_model: "Ram Van 3500", + car_year: 1999 + }, + { + id: 33, + car_make: "Jeep", + car_model: "Wrangler", + car_year: 2011 + }, + { + id: 34, + car_make: "Ford", + car_model: "Escort", + car_year: 1991 + }, + { + id: 35, + car_make: "Chrysler", + car_model: "300M", + car_year: 2000 + }, + { + id: 36, + car_make: "Volvo", + car_model: "XC70", + car_year: 2003 + }, + { + id: 37, + car_make: "Oldsmobile", + car_model: "LSS", + car_year: 1997 + }, + { + id: 38, + car_make: "Toyota", + car_model: "Camry", + car_year: 1992 + }, + { + id: 39, + car_make: "Ford", + car_model: "Econoline E250", + car_year: 1998 + }, + { + id: 40, + car_make: "Lotus", + car_model: "Evora", + car_year: 2012 + }, + { + id: 41, + car_make: "Ford", + car_model: "Mustang", + car_year: 1965 + }, + { + id: 42, + car_make: "GMC", + car_model: "Yukon", + car_year: 1996 + }, + { + id: 43, + car_make: "Mercedes-Benz", + car_model: "R-Class", + car_year: 2009 + }, + { + id: 44, + car_make: "Audi", + car_model: "Q7", + car_year: 2012 + }, + { + id: 45, + car_make: "Audi", + car_model: "TT", + car_year: 2008 + }, + { + id: 46, + car_make: "Oldsmobile", + car_model: "Ciera", + car_year: 1995 + }, + { + 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 + } ] /** * ### Challenge `getLastCarInfo` @@ -427,8 +676,8 @@ function getLastCarInfo(inv) { /* code here */ - console.log(`This is a ${data[inv.length-1].car_make},${data[inv.length-1].car_model}`) - + console.log(`This is a ${data[inv.length-1].car_make},${data[inv.length-1].car_model}`) + } getLastCarInfo(data) @@ -442,17 +691,17 @@ getLastCarInfo(data) * getModelYears returns an array containing all the 'car_year's in the inventory. */ - + function getModelYears(inv) { /* code here */ - const years=[]; + const years = []; - for(let i=0; i Date: Fri, 15 May 2020 15:23:13 -0400 Subject: [PATCH 12/12] Updated gertCarinfoById --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 48aaa8400..38f6517d8 100644 --- a/index.js +++ b/index.js @@ -730,7 +730,7 @@ function getCarInfoById(make, model) { return `This is a ${MAKE} ${MODEL}` } -console.log(getCarInfoById(1, 1)); +console.log(getCarInfoById(0, 0)); /** * ### Challenge `getOlderCars`