diff --git a/index.js b/index.js index bdafe4c8b..9d8efdc1b 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,8 @@ 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(degrees) { + return Math.round(degrees * (9/5) + 32); } /** @@ -74,8 +74,12 @@ function temperatureCtoF(/* code here */) { * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { - /* code here */ +function temperatureInF(degrees, unit) { + if (unit === 'F') { + return Math.round(degrees) + unit; + } else { + return temperatureCtoF(degrees) + 'F'; + } } @@ -95,8 +99,12 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +function makePersonObject(id, name, email) { + let person = new Object(); + person.id = id; + person.name = name; + person.email = email; + return person; } /** @@ -112,8 +120,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 +140,9 @@ 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) { + const applePosition = fruits.indexOf('apple'); + return applePosition; } /** @@ -151,10 +160,19 @@ 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) { + var appleList = []; + + for (let i = 0; i < fruits.length; i++){ + if (fruits[i] === 'apple'){ + appleList.push(true); + } else { + appleList.push(false); + } + } return appleList; + } + /* @@ -210,7 +228,8 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { - /* code here */ + var makeModel = inventory[index]; + return `This is a ${makeModel.car_make} ${makeModel.car_model}.` } /** @@ -224,8 +243,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) { + var inventoryLength = ((inventory.length) -1); + var lastCar = inventory[inventoryLength]; + return `This is a ${lastCar.car_make} ${lastCar.car_model}.` } /** @@ -237,8 +258,14 @@ 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) { + var carAge = []; + + for (let i = 0; i