From 51be64dcfa94051e7545f90a422f74b6d577626f Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Wed, 22 Apr 2020 15:49:52 -0500 Subject: [PATCH 1/8] passed first 2 exercises --- index.js | 215 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 120 insertions(+), 95 deletions(-) diff --git a/index.js b/index.js index bdafe4c8b..e6156e9c5 100644 --- a/index.js +++ b/index.js @@ -2,90 +2,92 @@ /** * ### Challenge `addNumbers` - * + * * @instructions * This function should be able to take two numbers as arguments * and return the result of adding them together. - * + * * For example, if we invoke `addNumbers` passing 5 and 3, * the returned value should be 8. * * NOTE: This example has been completed for you. -*/ + */ function addNumbers(num1, num2) { return num1 + num2; } // ⭐️ Example Challenge end ⭐️ - // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 /** * ### Challenge `sayGoodbye` - * + * * @instructions * This function should take an a name as an argument, * and return a string that says 'Goodbye, {name}. Have a great day.' - * + * * For example, if we invoke `sayGoodbye` * passing 'Andy' as the argument, * 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."; } /** * ### Challenge `temperatureCtoF` - * + * * @instructions * This function should take an a temperature in celsius as an argument, - * and return the temperature in fahrenheit, rounded to the nearest whole number. - * + * and return the temperature in fahrenheit, rounded to the nearest whole number. + * * For example, if we invoke `temperatureCtoF` * passing 24 as the argument, * the returned value should be: 75 - * + * * 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 */ + * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. + */ +function temperatureCtoF(temperature) { + return Math.round((temperature * 9) / 5 + 32); } /** * ### Challenge `temperatureInF` - * + * * @instructions * This function should take an a temperature and a unit (either 'F' or 'C') as arguments, - * and return the temperature in fahrenheit, rounded to the nearest whole number. - * + * and return the temperature in fahrenheit, rounded to the nearest whole number. + * * For example, if we invoke `temperatureInF` * passing 88, 'F' as the arguments, * the returned value should be: '88F' - * + * * If we invoke `temperatureInF` * passing 24, 'C' as the arguments, * the returned value should be: '75F' - * + * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. -*/ -function temperatureInF(/* code here */) { - /* code here */ + */ +function temperatureInF(temperature, cOrF) { + if (cOrF == "C" || "c") { + return temperatureCtoF(temperature) + "F"; + } else { + return temperature + "F"; + } } - /** * ### Challenge `makePersonObject` - * + * * @instructions * This function should take an id, a name and an email as arguments, * and return an object with `id`, `name` and `email` properties. - * + * * For example, if we invoke `makePersonObject` * passing 5, 'Leia' and 'leia@leia.com' as arguments, * the returned value should look like: @@ -94,69 +96,66 @@ function temperatureInF(/* code here */) { * name: "Leia", * email: "leia@leia.com", * } -*/ + */ function makePersonObject(/* code here */) { /* code here */ } /** * ### Challenge `getName` - * + * * @instructions * This function takes as its only argument * an object containing a `name` property, * and return a string that reads `Hello, my name is {name}`, * where `{name}` is the name stored in the object. - * + * * 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 */) { /* code here */ } - /** * ### Challenge `appleIndex` - * + * * @instructions - * This function takes as its only argument an array + * This function takes as its only argument an array * containing strings, * and returns the index in the array of the string 'apple'. - * - * You may assume the string 'apple' will appear exactly + * + * You may assume the string 'apple' will appear exactly * once in the array. - * + * * 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 */) { /* code here */ } /** * ### Challenge `isItAnApple` - * + * * @instructions - * This function takes as its only argument an array + * This function takes as its only argument an array * containing strings, * and returns an array of equal length containing the `true` - * if the corresponding entry in the original array is 'apple' + * if the corresponding entry in the original array is 'apple' * and `false` if it is anything else. - * - * + * + * * 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 */) { /* code here */ } - - /* // ⭐️ Example Test Data ⭐️ @@ -179,64 +178,63 @@ var inventory = [ ] */ /** - * ### 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}` + return `The is a ${the3rd.car_make} ${the3rd.car_model}`; } // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 // 👇 COMPLETE YOUR WORK BELOW 👇 - /** * ### Challenge `getCarInfoByIndex` - * + * * @instructions * getCarInfoByIndex takes two arguments: * (1) an array which is an inventory of cars like the preview above (see ⭐️ Preview Test Data ⭐️) * (2) a number which is the desired index in the array. * getCarInfoByIndex returns a string in the format `This is a {car_make} {car_model}` - * + * * 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 */ } /** * ### Challenge `getLastCarInfo` - * + * * @instructions * getLastCarInfo takes a single argument: * (1) an array which is an inventory of cars like the one inside /data/inventory.js. * getLastCarInfo returns a string in the format `This is a {car_make} {car_model} - * + * * 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 */ } /** * ### Challenge `getModelYears` - * + * * @instructions * We need the years from every car in the inventory! * 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 */) { /* code here */ } @@ -245,16 +243,16 @@ function getModelYears(/* code here */) { * ### Challenge `getCarInfoById` * * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * + * * @instructions * getCarInfoById takes two arguments: * (1) an array which is an inventory of cars like the one inside /data/inventory.js. * (2) a number which is the desired car id (see how each car has its own unique id). * getCarInfoById returns a string in the format `This is a {car_make} {car_model} - * + * * 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 */ } @@ -263,7 +261,7 @@ function getCarInfoById(/* code here */) { * ### Challenge `getOlderCars` * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * + * * @instructions * We need a utility to find older cars! * getOlderCars takes two arguments: @@ -272,7 +270,7 @@ 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 */) { /* code here */ } @@ -281,7 +279,7 @@ function getOlderCars(/* code here */) { * ### Challenge `getGermanCars` * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * + * * @instructions * We need a utility to find German cars! * getGermanCars takes a single argument: @@ -289,7 +287,7 @@ 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 */) { /* code here */ } @@ -298,7 +296,7 @@ function getGermanCars(/* code here */) { * ### Challenge `carMaker` * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! - * + * * @instructions * This function takes a single odometer argument (a number) and returns an object. * The returned object has the following characteristics: @@ -306,7 +304,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 */) { /* code here */ } @@ -314,29 +312,56 @@ function carMaker(/* code here */) { /// ////// END OF CHALLENGE ///////// /// ////// END OF CHALLENGE ///////// /// ////// END OF CHALLENGE ///////// -if (typeof exports !== 'undefined') { +if (typeof exports !== "undefined") { // IGNORE: Test/Env Detected // For Node/Non-browser test env - module.exports = module.exports || {} - if (addNumbers) { module.exports.addNumbers = addNumbers } - if (sayGoodbye) { module.exports.sayGoodbye = sayGoodbye } - if (temperatureCtoF) { module.exports.temperatureCtoF = temperatureCtoF } - if (temperatureInF) { module.exports.temperatureInF = temperatureInF } - if (makePersonObject) { module.exports.makePersonObject = makePersonObject } - if (getName) { module.exports.getName = getName } - if (appleIndex) { module.exports.appleIndex = appleIndex } + module.exports = module.exports || {}; + if (addNumbers) { + module.exports.addNumbers = addNumbers; + } + if (sayGoodbye) { + module.exports.sayGoodbye = sayGoodbye; + } + if (temperatureCtoF) { + module.exports.temperatureCtoF = temperatureCtoF; + } + if (temperatureInF) { + module.exports.temperatureInF = temperatureInF; + } + if (makePersonObject) { + module.exports.makePersonObject = makePersonObject; + } + if (getName) { + module.exports.getName = getName; + } + if (appleIndex) { + module.exports.appleIndex = appleIndex; + } - if (isItAnApple) { module.exports.isItAnApple = isItAnApple } - + if (isItAnApple) { + module.exports.isItAnApple = isItAnApple; + } - - if (carMaker) { module.exports.carMaker = carMaker } - if (getCarInfoByIndex) { module.exports.getCarInfoByIndex = getCarInfoByIndex } - if (getLastCarInfo) { module.exports.getLastCarInfo = getLastCarInfo } - if (getCarInfoById) { module.exports.getCarInfoById = getCarInfoById } + if (carMaker) { + module.exports.carMaker = carMaker; + } + if (getCarInfoByIndex) { + module.exports.getCarInfoByIndex = getCarInfoByIndex; + } + if (getLastCarInfo) { + module.exports.getLastCarInfo = getLastCarInfo; + } + if (getCarInfoById) { + module.exports.getCarInfoById = getCarInfoById; + } - if (getModelYears) { module.exports.getModelYears = getModelYears } - if (getOlderCars) { module.exports.getOlderCars = getOlderCars } - if (getGermanCars) { module.exports.getGermanCars = getGermanCars } - + if (getModelYears) { + module.exports.getModelYears = getModelYears; + } + if (getOlderCars) { + module.exports.getOlderCars = getOlderCars; + } + if (getGermanCars) { + module.exports.getGermanCars = getGermanCars; + } } From ef1f2f2b0714b765a55a488ae6999dd02229602c Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Wed, 22 Apr 2020 18:53:54 -0500 Subject: [PATCH 2/8] passed #7 getName --- index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index e6156e9c5..daa3213fc 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ function sayGoodbye(name) { * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. */ function temperatureCtoF(temperature) { - return Math.round((temperature * 9) / 5 + 32); + return Math.round(temperature * 9 / 5 + 32); } /** @@ -74,10 +74,10 @@ function temperatureCtoF(temperature) { * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ function temperatureInF(temperature, cOrF) { - if (cOrF == "C" || "c") { + if (cOrF === "C") { return temperatureCtoF(temperature) + "F"; } else { - return temperature + "F"; + return temperature + cOrF; } } @@ -97,8 +97,13 @@ function temperatureInF(temperature, cOrF) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +function makePersonObject(id, name, email) { + let personInfo = { + id: id, + name: name, + email: email, + }; + return personInfo; } /** @@ -114,8 +119,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(object) { + return `Hello, my name is ${object.name}`; } /** @@ -133,8 +138,10 @@ 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(fruit arr) { + if (fruit arr == apple) { + appleIndex + } } /** From 48dabfa7b94bcff7f62c3a0dce981b8000f2d330 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Wed, 22 Apr 2020 21:04:09 -0500 Subject: [PATCH 3/8] stuck on appleIndex for a while --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index daa3213fc..68b109997 100644 --- a/index.js +++ b/index.js @@ -138,12 +138,14 @@ function getName(object) { * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex(fruit arr) { - if (fruit arr == apple) { - appleIndex - } +function appleIndex(fruitArray) { + let index; + for (i = 0; i < fruitArray.length; i++ +) { + return index; + } if () } + /** * ### Challenge `isItAnApple` * From 255119b4b6c53c4538e2a7f4269e08f8e6efa91e Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Thu, 23 Apr 2020 12:46:50 -0500 Subject: [PATCH 4/8] appleIndex is finally passed --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 68b109997..b9f6e9adc 100644 --- a/index.js +++ b/index.js @@ -139,10 +139,8 @@ function getName(object) { * the returned value should be: 2. */ function appleIndex(fruitArray) { - let index; - for (i = 0; i < fruitArray.length; i++ +) { - return index; - } if () + let index = fruitArray.indexOf('apple'); + return index; } From 57ddd1bb4b86f6ada095147632c915fd34d0c346 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Thu, 23 Apr 2020 16:40:07 -0500 Subject: [PATCH 5/8] trying to solve isItAnApple delimma --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b9f6e9adc..9978bc196 100644 --- a/index.js +++ b/index.js @@ -159,8 +159,11 @@ function appleIndex(fruitArray) { * 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) { + let newArray = []; + for (let i = 0; i < Array.length; i++) { + (Array[i] === 'apple') ? newArray.push(true) : newArray.push(false); + } return newArray } /* From 5058cdb71f154659ea2471f5b2decc5c31d95436 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Thu, 23 Apr 2020 18:11:17 -0500 Subject: [PATCH 6/8] passed up to getCarInfoByIndex --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9978bc196..fe572691d 100644 --- a/index.js +++ b/index.js @@ -218,7 +218,8 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { - /* code here */ + const carInfo = inventory[index]; + return `This is a ${carInfo.car_make} ${carInfo.car_model}`; } /** From 3940a102b7bd50f7efe61265a93894b95d97e4b0 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Thu, 23 Apr 2020 19:09:40 -0500 Subject: [PATCH 7/8] passed all MVP YAAAAY --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fe572691d..f41c4a716 100644 --- a/index.js +++ b/index.js @@ -233,8 +233,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 index = Array[Array.length - 1]; + return `This is a ${index.car_make} ${index.car_model}`; } /** From fa376ba5abadc90d1e51237da975a6330d498477 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Tue, 28 Apr 2020 23:43:31 -0500 Subject: [PATCH 8/8] missed the Last MVP, so I did it tonight --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f41c4a716..284a73aa2 100644 --- a/index.js +++ b/index.js @@ -247,8 +247,12 @@ function getLastCarInfo(Array) { * (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(carArray) { + let modelYears = []; + for (let i = 0; i < carArray.length; i++) { + modelYears.push(carArray[i].car_year); + } + return modelYears; } /**