Skip to content

MVP #133

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

MVP #133

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
117 changes: 92 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
*
Expand All @@ -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`
Expand All @@ -96,10 +107,31 @@ function temperatureInF(/* code here */) {
* email: "[email protected]",
* }
*/
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","[email protected]"));
makePersonObject(5,"Daniel","[email protected]");
/**
* ### Challenge `getName`
*
Expand All @@ -113,10 +145,15 @@ 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(object) {
return (`Hello, my name is ${this.name}`);
}

const newPerson = {
id : 5,
name : "Daniel",
email : "[email protected]",
};
console.log(getName(newPerson));

/**
* ### Challenge `appleIndex`
Expand All @@ -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`
Expand All @@ -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 ⭐️
Expand Down Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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
Expand All @@ -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`
Expand Down