Skip to content

Sawyer.pearson #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
116 changes: 87 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}

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

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


Expand All @@ -95,8 +99,12 @@ function temperatureInF(/* code here */) {
* email: "[email protected]",
* }
*/
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;
}

/**
Expand All @@ -112,8 +120,8 @@ function makePersonObject(/* code here */) {
* passing { id: 1, name: 'Leia', email: '[email protected]` } 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 + '.' ;
}


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

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



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

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

/**
Expand All @@ -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 <inventory.length; i++){
var carInfo = Object.values(inventory[i])
carAge.push(carInfo[3]);
} return carAge;

}

/**
Expand All @@ -251,12 +278,15 @@ function getModelYears(/* code here */) {
* (1) an array which is an inventory of cars like the one inside /data/inventory.js.
* (2) a number which is the desired car id (see how each car has its own unique id).
* getCarInfoById returns a string in the format `This is a {car_make} {car_model}
*
*
* 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, id) {
var carNumber = (id - 1)
var selectedIndex = inventory[carNumber];
return `This is a ${selectedIndex.car_make} ${selectedIndex.car_model}`;

}

/**
Expand All @@ -273,8 +303,15 @@ 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 */) {
/* code here */
function getOlderCars(inventory, age) {
var carAges = [];

for (let i = 0; i < inventory.length; i++){
var carInfo = Object.values(inventory[i]);
if (carInfo[3] <= age){
carAges.push(inventory[i]);
}
}return carAges;
}

/**
Expand All @@ -290,8 +327,27 @@ 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 */) {
/* code here */
function getGermanCars(inventory) {
var imports = [];

for (let i = 0; i < inventory.length; i++){
var carInfo = Object.values(inventory[i]);
if (carInfo[1] === 'Audi'){
imports.push(inventory[i]);
}
else
if (carInfo[1] === 'Mercedes-Benz'){
imports.push(inventory[i]);
}
else
if (carInfo[1] === 'Volkswagen'){
imports.push(inventory[i]);
}
else
if (carInfo[1] === 'BMW'){
imports.push(inventory[i]);
}
}return imports;
}

/**
Expand All @@ -307,8 +363,10 @@ 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 */) {
/* code here */
function carMaker(miles) {
let car = new Object()
car.odometer = miles;
return car;
}

/// ////// END OF CHALLENGE /////////
Expand Down
Loading