From 5f594bfa1f7f46c07ca39c65f4c253413f0c9425 Mon Sep 17 00:00:00 2001 From: Daniel Terry Date: Wed, 27 May 2020 23:56:16 -0400 Subject: [PATCH] MVP --- index.js | 117 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 3a474a3f4..a43a744cf 100644 --- a/index.js +++ b/index.js @@ -36,9 +36,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(name) { + return `Goodbye, ${name}. Have a great day.`; } +console.log(sayGoodbye("daniel")); /** * ### Challenge `temperatureCtoF` @@ -54,10 +55,11 @@ 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(temp) { + return Math.round(temp * (9/5) + 32); /* code here */ } - +console.log(temperatureCtoF(24)); /** * ### Challenge `temperatureInF` * @@ -75,10 +77,19 @@ function temperatureCtoF(/* code here */) { * * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. */ -function temperatureInF(/* code here */) { +function temperatureInF(temp,unit) { +if(unit === "F"){ + return (temp + unit); +} +else if(unit === "C"){ + //let newTemp = + //temperatureCtoF(temp); + //let newTemp = (Math.round(temp * (9/5) + 32)); + return temperatureCtoF(temp); //(`${newTemp}F`); +} /* code here */ } - +console.log(temperatureInF(24,"C")); /** * ### Challenge `makePersonObject` @@ -96,10 +107,31 @@ function temperatureInF(/* code here */) { * email: "leia@leia.com", * } */ -function makePersonObject(/* code here */) { - /* code here */ +/* + class personObject{ + constructor(id,name,email) { + this.id = id; + this.name = name; + this.email = email; + } - +} +let person1 = new personObject(5,"Daniel","Daniel@gmail"); +console.log(person1); +*/ +function makePersonObject(id,name,email){ + const newPerson = { + id : id, + name : name, + email : email, + }; + //"ID:" + this.id + " " + "Name:" + this.name + " " + "Email:" + this.email; + return newPerson; + +} + +console.log(makePersonObject(5,"Daniel","Dterry123@gmail.com")); +makePersonObject(5,"Daniel","Dterry123@gmail.com"); /** * ### Challenge `getName` * @@ -113,10 +145,15 @@ 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 ${this.name}`); } - +const newPerson = { + id : 5, + name : "Daniel", + email : "daniel.terry2121@gmail.com", + }; +console.log(getName(newPerson)); /** * ### Challenge `appleIndex` @@ -133,9 +170,11 @@ 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) { + var a = array.indexOf("apple"); + return a; } +console.log(appleIndex(["orange", "grape", "apple", "banana", "mango" ])); /** * ### Challenge `isItAnApple` @@ -149,14 +188,24 @@ function appleIndex(/* code here */) { * * * For example, if we invoke `isItAnApple` - * passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument, + * passing in [ 'orange', 'apple', 'banana', 'apple', '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) { +for(i=0; i < array.length; i++){ + if(array[i] == "apple"){ + console.log ("true"); + } + else{ + console.log("false"); } + /* code here */ +} +} +console.log(isItAnApple([ "orange", "apple", "banana", "apple", "apple", "mango" ])); + // ⭐️ Example Test Data ⭐️ @@ -210,8 +259,12 @@ function get3rdCar(inventory) { * it will return `This is a Lincoln Navigator`. */ function getCarInfoByIndex(inventory, index) { - /* code here */ + const carByIndex = inventory[index]; + console.log(`This is a ${carByIndex.car_make} ${carByIndex.car_model}`); + return `This is a ${carByIndex.car_make} ${carByIndex.car_model}` } +getCarInfoByIndex(inventory,0); + /** * ### Challenge `getLastCarInfo` @@ -224,9 +277,13 @@ 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) { + //const lastItem = inventory.length - -1; + const lastCar = inventory[inventory.length-1]; + console.log(`This is a ${lastCar.car_make} ${lastCar.car_model}`); + return lastCar; } +getLastCarInfo(inventory); /** * ### Challenge `getModelYears` @@ -237,10 +294,15 @@ 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) { +const carYears = []; +for (i = 0; i < inventory.length; i++) { +carYears.push(inventory[i].car_year); } - +console.log(carYears); +} + //return modelYears; +getModelYears(inventory); /** * ### Challenge `getCarInfoById` * * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER @@ -255,9 +317,14 @@ 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(inventory) { +const carId = []; +for (i = 0; i < inventory.length; i++) { +carId.push(inventory[i].id); +} +console.log(carId); } +}getCarInfoByID(inventory); /** * ### Challenge `getOlderCars`