diff --git a/index.js b/index.js index bdafe4c8b..8751f94e5 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ // ⭐️ Example Challenge start ⭐️ - +//comment /** * ### Challenge `addNumbers` * @@ -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,13 @@ 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`){ + return `${temperature}F`; + } + else { + return `${temperatureCtoF(temperature)}F`; + } } @@ -95,8 +101,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 +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(person) { + return `Hello, my name is ${person.name}` } @@ -132,8 +139,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 +162,21 @@ 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++) + { + if(array[i] === `apple`){ + results.push(true); + } + else{ + results.push(false)} + + } + return results; } - /* // ⭐️ Example Test Data ⭐️ @@ -210,7 +230,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 +245,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 +259,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; } /** @@ -255,8 +282,12 @@ 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 */) { - /* 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}` + } + } } /** @@ -273,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(/* code here */) { - /* 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; } /** @@ -290,8 +327,16 @@ function getOlderCars(/* code here */) { * 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; } /** @@ -307,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){ + this.odometer +=distance; + return this.odometer;} + } + return car; } /// ////// END OF CHALLENGE /////////