Skip to content

completted #124

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 1 commit into
base: master
Choose a base branch
from
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
79 changes: 53 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function addNumbers(num1, num2) {
// 👇 COMPLETE YOUR WORK BELOW 👇

/**
* ### Challenge `sayGoodbye`
* ### Challenge `sayGoodbye`
*
* @instructions
* This function should take an a name as an argument,
Expand All @@ -35,10 +35,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 (noah){
return (`Goodbye, ${noah}. Have a great day.`);
}

console.log(sayGoodbye)
/**
* ### Challenge `temperatureCtoF`
*
Expand All @@ -53,10 +53,12 @@ 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(celsius) {
let fahrenheit
fahrenheit = celsius * 9 / 5 + 32;
return Math.round (fahrenheit);
}

temperatureCtoF(24);
/**
* ### Challenge `temperatureInF`
*
Expand All @@ -74,9 +76,14 @@ function temperatureCtoF(/* code here */) {
*
* Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`.
*/
function temperatureInF(/* code here */) {
/* code here */
}
function temperatureInF(temp, unit) {
if (unit =='F'){
return `${temp}${unit}`;
}else{
return `${temperatureCtoF(temp)}F`;
}
}



/**
Expand All @@ -95,10 +102,10 @@ function temperatureInF(/* code here */) {
* email: "[email protected]",
* }
*/
function makePersonObject(/* code here */) {
/* code here */
function makePersonObject(id, name, email){
return {id, name, email};
}

console.log(makePersonObject('5', 'Leia', '[email protected]'));
/**
* ### Challenge `getName`
*
Expand All @@ -112,10 +119,10 @@ 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}`
}

console.log(getName)

/**
* ### Challenge `appleIndex`
Expand All @@ -132,10 +139,15 @@ 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) {
for (let i = 0; i < fruits.length; i++){
if (fruits[i] === 'apple'){
return i
}
}
}


/**
* ### Challenge `isItAnApple`
*
Expand All @@ -151,8 +163,16 @@ 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) {
let temporaryArray = []
for (let i = 0; i < fruits.length; i++){
if (fruits[i] === 'apple'){
temporaryArray.push(true)
} else {
temporaryArray.push(false)
}
}
return temporaryArray
}


Expand Down Expand Up @@ -210,9 +230,10 @@ function get3rdCar(inventory) {
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoByIndex(inventory, index) {
/* code here */
let the1st = inventory[0];
return `This is a ${the1st.car_make} ${the1st.car_model}`
}

console.log(getCarInfoByIndex)
/**
* ### Challenge `getLastCarInfo`
*
Expand All @@ -224,8 +245,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) {
let last = inventory.length;

return `This is a ${inventory[last-1].car_make} ${inventory[last-1].car_model}`
}

/**
Expand All @@ -237,8 +260,12 @@ 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) {
let years = []
for (let i = 0; i < inventory.length; i++){
years[i] = inventory[i].car_year
}
return years
}

/**
Expand Down