diff --git a/index.js b/index.js index bdafe4c8b..177573326 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ function addNumbers(num1, num2) { // 👇 COMPLETE YOUR WORK BELOW 👇 /** - * ### Challenge `sayGoodbye` +* ### Challenge `sayGoodbye` * * @instructions * This function should take an a name as an argument, @@ -35,10 +35,10 @@ function addNumbers(num1, num2) { * the returned value should look like: 'Goodbye, Andy. Have a great day.' * */ -function sayGoodbye(/* code here */) { - /* code here */ +function sayGoodbye (noah){ + return (`Goodbye, ${noah}. Have a great day.`); } - +console.log(sayGoodbye) /** * ### Challenge `temperatureCtoF` * @@ -53,10 +53,12 @@ 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) { + let fahrenheit + fahrenheit = celsius * 9 / 5 + 32; + return Math.round (fahrenheit); } - +temperatureCtoF(24); /** * ### Challenge `temperatureInF` * @@ -74,9 +76,14 @@ function temperatureCtoF(/* code here */) { * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { - /* code here */ -} +function temperatureInF(temp, unit) { + if (unit =='F'){ + return `${temp}${unit}`; + }else{ + return `${temperatureCtoF(temp)}F`; + } + } + /** @@ -95,10 +102,10 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +function makePersonObject(id, name, email){ + return {id, name, email}; } - +console.log(makePersonObject('5', 'Leia', 'leia@leia.com')); /** * ### Challenge `getName` * @@ -112,10 +119,10 @@ 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}` } - +console.log(getName) /** * ### Challenge `appleIndex` @@ -132,10 +139,15 @@ 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(fruits) { + for (let i = 0; i < fruits.length; i++){ + if (fruits[i] === 'apple'){ + return i + } + } } + /** * ### Challenge `isItAnApple` * @@ -151,8 +163,16 @@ 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(fruits) { + let temporaryArray = [] + for (let i = 0; i < fruits.length; i++){ + if (fruits[i] === 'apple'){ + temporaryArray.push(true) + } else { + temporaryArray.push(false) + } + } + return temporaryArray } @@ -210,9 +230,10 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { - /* code here */ + let the1st = inventory[0]; + return `This is a ${the1st.car_make} ${the1st.car_model}` } - +console.log(getCarInfoByIndex) /** * ### Challenge `getLastCarInfo` * @@ -224,8 +245,10 @@ 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(inventory) { + let last = inventory.length; + + return `This is a ${inventory[last-1].car_make} ${inventory[last-1].car_model}` } /** @@ -237,8 +260,12 @@ 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(inventory) { + let years = [] + for (let i = 0; i < inventory.length; i++){ + years[i] = inventory[i].car_year + } + return years } /**