From ee0ac27e7fd009836559efd84d6a55a59948b277 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 Mar 2020 18:26:37 -0400 Subject: [PATCH] completed all challenges --- index.js | 122 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index bdafe4c8b..4772fe191 100644 --- a/index.js +++ b/index.js @@ -35,7 +35,8 @@ function addNumbers(num1, num2) { * the returned value should look like: 'Goodbye, Andy. Have a great day.' * */ -function sayGoodbye(/* code here */) { +function sayGoodbye(name) { + return `Goodbye, ${name}. Have a great day.` /* code here */ } @@ -53,7 +54,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 */) { +function temperatureCtoF(cel) { + let y = (cel* 9/5) +32; + return Math.round(y) /* code here */ } @@ -74,7 +77,14 @@ function temperatureCtoF(/* code here */) { * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { +function temperatureInF(tem,type) { + + if (type === 'C'){ + return temperatureCtoF(tem) + 'F' + + }else{ + return Math.round(tem) + type + } /* code here */ } @@ -95,7 +105,12 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { +function makePersonObject(id,name,email) { + let myobj = {} + myobj.id = id; + myobj.name = name; + myobj.email = email; + return myobj /* code here */ } @@ -112,7 +127,9 @@ 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 */) { +function getName(obj) { + let who = obj.name; + return `Hello, my name is ${who}` /* code here */ } @@ -132,7 +149,8 @@ function getName(/* code here */) { * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, * the returned value should be: 2. */ -function appleIndex(/* code here */) { +function appleIndex(arr) { + return arr.indexOf('apple') /* code here */ } @@ -151,7 +169,17 @@ 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 */) { +function isItAnApple(arr) { + let arr2 = [] + for(let i = 0; i < arr.length; i++){ + if(arr[i] === 'apple'){ + arr2.push(true) + }else{ + arr2.push(false) + } + + } + return arr2 /* code here */ } @@ -210,6 +238,10 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { + let make = inventory[index].car_make; + let model = inventory[index].car_model; + + return `This is a ${make} ${model}` /* code here */ } @@ -224,7 +256,12 @@ 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 */) { +function getLastCarInfo(arr) { + let make = arr[arr.length - 1].car_make; + let model = arr[arr.length - 1].car_model; + + return `This is a ${make} ${model}` + /* code here */ } @@ -237,7 +274,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 */) { +function getModelYears(arr) { + let years =[]; + for(let i =0; i < arr.length; i++){ + years.push(arr[i].car_year); + + } + + return years /* code here */ } @@ -255,7 +299,18 @@ 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 */) { +function getCarInfoById(arr,id) { + var make; + var model; + + for(let i = 0; i