From caef0a080143fd20de4c61a54b9c5f16691ac9b9 Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Wed, 22 Apr 2020 00:16:33 -0400 Subject: [PATCH 1/6] original --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index bdafe4c8b..66cf4a5a8 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ // ⭐️ Example Challenge start ⭐️ - +//comment /** * ### Challenge `addNumbers` * From 84aec667d754f5463b48e5b44809f3240acb23ab Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Wed, 22 Apr 2020 21:57:25 -0400 Subject: [PATCH 2/6] new functions --- index.js | 72 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 66cf4a5a8..100f61ca6 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,8 @@ function addNumbers(num1, num2) { * the returned value should look like: 'Goodbye, Andy. Have a great day.' * */ -function sayGoodbye(/* code here */) { - /* code here */ +function sayGoodbye(name) { + return `Goodbye, ${name}. Have a great day.` } /** @@ -53,8 +53,9 @@ function sayGoodbye(/* code here */) { * 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 */) { - /* code here */ +function temperatureCtoF(celsius) { + const fahrenheit = Math.round((celsius * (9/5)) + 32); + return fahrenheit; } /** @@ -74,8 +75,15 @@ function temperatureCtoF(/* code here */) { * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { - /* code here */ +function temperatureInF(temperature, unit) { + if(unit === `F` || `f`){ + return `${temperature}F` + } + else if (unit === `C` || `c`){ + let newTemp = temperatureCtoF(temperature); + return `${newTemp}F` + } + } @@ -95,8 +103,9 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +function makePersonObject(id, name, email) { + const person = {id, name, email} + return person; } /** @@ -112,8 +121,8 @@ function makePersonObject(/* code here */) { * 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(person) { + return `Hello, my name is ${person.name}` } @@ -132,8 +141,12 @@ function getName(/* code here */) { * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex(/* code here */) { - /* code here */ +function appleIndex(array) { + for(i=0; i < array.length; i++){ + if(array[i] === `apple`){ + return i; + } + } } /** @@ -151,12 +164,24 @@ function appleIndex(/* code here */) { * 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 */) { - /* code here */ +function isItAnApple(array) { + // const results = []; + // for (i=0; i < array.length; i++) + // { + // for(i=0; i < array[i].length; i++){ + // if(array[i] === `apple`){ + // let true = `true`; + // results.push(true); + // } + // else + // let false = `false`; + // results.push(false) + // } + // } + // return results; } - /* // ⭐️ Example Test Data ⭐️ @@ -210,7 +235,8 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { - /* code here */ + const car = inventory[index] + return `This is a ${car.car_make} ${car.car_model}` } /** @@ -224,8 +250,9 @@ 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 */) { - /* code here */ +function getLastCarInfo(array) { + const last = (array.length - 1) + return `This is a ${array[last].car_make} ${array[last].car_model}` } /** @@ -237,8 +264,13 @@ 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 */) { - /* code here */ +function getModelYears(array) { + const results = []; + for(i=0; i < array.length; i++){ + let year = array[i].car_year; + results.push(year); + } + return results; } /** From 23fe773fb53801b820dd74a5e7fc29caa230f88f Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Wed, 22 Apr 2020 22:48:16 -0400 Subject: [PATCH 3/6] temperature function --- index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 100f61ca6..d32c87f3c 100644 --- a/index.js +++ b/index.js @@ -76,14 +76,12 @@ function temperatureCtoF(celsius) { * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ function temperatureInF(temperature, unit) { - if(unit === `F` || `f`){ - return `${temperature}F` + if(unit === `F`){ + return `${temperature}F`; } - else if (unit === `C` || `c`){ - let newTemp = temperatureCtoF(temperature); - return `${newTemp}F` - } - + else { + return `${temperatureCtoF(temperature)}F`; + } } From 4caafd3b2c2173ba35f3ab24e93a20641d7e0288 Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Wed, 22 Apr 2020 23:12:21 -0400 Subject: [PATCH 4/6] isApple function --- index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index d32c87f3c..117367283 100644 --- a/index.js +++ b/index.js @@ -163,20 +163,17 @@ function appleIndex(array) { * the returned value should be: [ false, true, false, false, true, false ]. */ function isItAnApple(array) { - // const results = []; - // for (i=0; i < array.length; i++) - // { - // for(i=0; i < array[i].length; i++){ - // if(array[i] === `apple`){ - // let true = `true`; - // results.push(true); - // } - // else - // let false = `false`; - // results.push(false) - // } - // } - // return results; + const results = []; + for (i=0; i < array.length; i++) + { + if(array[i] === `apple`){ + results.push(true); + } + else{ + results.push(false)} + + } + return results; } @@ -303,7 +300,7 @@ 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 */) { +function getOlderCars(array,maxYear) { /* code here */ } From e5cc76e036a12359e0e9ed4d8635854ab185f992 Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Thu, 23 Apr 2020 00:30:14 -0400 Subject: [PATCH 5/6] added functions --- index.js | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 117367283..6e0998dca 100644 --- a/index.js +++ b/index.js @@ -282,8 +282,12 @@ function getModelYears(array) { * 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 */) { - /* code here */ +function getCarInfoById(array, id) { + for(i=0; i < array.length; i++){ + if(array[i].id === id){ + return `This is a ${array[i].car_make} ${array[i].car_model}` + } + } } /** @@ -300,8 +304,14 @@ 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(array,maxYear) { - /* code here */ +function getOlderCars(array, maxYear) { + const results = [] + for(i=0; i < array.length; i++){ + if(array[i].car_year <= maxYear){ + results.push(array[i]); + } + } + return results; } /** @@ -317,8 +327,16 @@ function getOlderCars(array,maxYear) { * 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 */) { - /* code here */ + +function getGermanCars(arr){ + const result = []; + + for(let i = 0; i < arr.length; i++){ + if (arr[i].car_make === 'Audi' || arr[i].car_make === 'Mercedes-Benz' || arr[i].car_make === 'Volkswagen' || arr[i].car_make === 'BMW'){ + result.push(arr[i]); + } + } + return result; } /** @@ -334,8 +352,14 @@ function getGermanCars(/* code here */) { * (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 */) { - /* code here */ +function carMaker(number) { +// const car = { +// odometer: number, +// drive: function(distance){ +// const newDistance = car.odometer + distance; +// return newDistance; +// } +// return `${car}`; } /// ////// END OF CHALLENGE ///////// From d176a6c157a21606517143026fa682644382335a Mon Sep 17 00:00:00 2001 From: karlamartinezmoctez Date: Fri, 24 Apr 2020 22:01:39 -0400 Subject: [PATCH 6/6] final stretch --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 6e0998dca..8751f94e5 100644 --- a/index.js +++ b/index.js @@ -353,13 +353,13 @@ function getGermanCars(arr){ * (2) returns the updated value of the `odometer`. */ function carMaker(number) { -// const car = { -// odometer: number, -// drive: function(distance){ -// const newDistance = car.odometer + distance; -// return newDistance; -// } -// return `${car}`; + const car = { + odometer: number, + drive: function(distance){ + this.odometer +=distance; + return this.odometer;} + } + return car; } /// ////// END OF CHALLENGE /////////