Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 109 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand Down Expand Up @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 */
}

Expand All @@ -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 <arr.length; i++){
if(arr[i].id === id){
make = arr[i].car_make;
model = arr[i].car_model;

}
}
return `This is ${make} ${model}`
/* code here */
}

Expand All @@ -273,7 +328,17 @@ 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 */) {
function getOlderCars(arr,maxYear) {
let arr2 =[]
for(let i = 0; i < arr.length; i++){
if(arr[i].car_year <= maxYear){
arr2.push(arr[i])


}
}
return arr2;

/* code here */
}

Expand All @@ -290,7 +355,21 @@ 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 */) {
function getGermanCars(arr) {
let arr2 =[]
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'
){
arr2.push(arr[i])


}
}
return arr2
/* code here */
}

Expand All @@ -307,7 +386,24 @@ 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 */) {
function carMaker(num) {
let myobj={
odometer:num,

drive: function(dist){
let y = this.odometer + dist;
myobj.odometer = y
return myobj.odometer


}


}
return myobj



/* code here */
}

Expand Down