diff --git a/index.html b/index.html
index 33ca1105e..e45229a6d 100644
--- a/index.html
+++ b/index.html
@@ -1,6 +1,7 @@
+
Exercises
diff --git a/index.js b/index.js
index bdafe4c8b..553be0139 100644
--- a/index.js
+++ b/index.js
@@ -35,9 +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(name) {
+ return `Goodbye, ${name}. Have a great day.`;
+ }
+sayGoodbye('Andy');
/**
* ### Challenge `temperatureCtoF`
@@ -53,9 +54,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(tempctof) {
+ let tempf = (Math.round((tempctof*1.8)+32));
+ return tempf;
}
+temperatureCtoF(24);
/**
* ### Challenge `temperatureInF`
@@ -74,9 +78,21 @@ function temperatureCtoF(/* code here */) {
*
* Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`.
*/
-function temperatureInF(/* code here */) {
- /* code here */
+function temperatureInF(tempVal, Tunit) {
+let tempf;
+ if (Tunit == 'F')
+ {
+ return tempVal+'F';
+ }else if(Tunit == 'C')
+ {
+ tempf = (Math.round((tempVal*1.8)+32));
+ return tempf+'F';
+ }
}
+temperatureInF(66,'F');
+temperatureInF(104,'C');
+
+
/**
@@ -95,8 +111,13 @@ function temperatureInF(/* code here */) {
* email: "leia@leia.com",
* }
*/
-function makePersonObject(/* code here */) {
- /* code here */
+function makePersonObject(id, name, email) {
+ let madeObj ={
+ id:id,
+ name:name,
+ email:email
+ };
+ return madeObj;
}
/**
@@ -112,8 +133,8 @@ 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({ name }) {
+ return `Hello, my name is ${name}` ;
}
@@ -132,8 +153,13 @@ 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(arrFruit) {
+ //let apple;
+ for(let i = 0; i<= arrFruit.length-1;i++){
+ if(arrFruit[i] === 'apple'){
+ return i;
+ }
+ }
}
/**
@@ -151,8 +177,18 @@ 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(arrFruit) {
+ let newArr = [];
+ //let firstVal = true;
+ //let secondVal = false;
+ for(let i = 0; i<=arrFruit.length-1; i++){
+ if(arrFruit[i] === "apple"){
+ newArr.push(true);
+ }else{
+ newArr.push(false);
+ }
+ };
+ return newArr;
}
@@ -189,7 +225,7 @@ var inventory = [
**/
function get3rdCar(inventory) {
const the3rd = inventory[2];
- return `The is a ${the3rd.car_make} ${the3rd.car_model}`
+ return `The is a ${the3rd.car_make} ${the3rd.car_model}`;
}
// 👇 COMPLETE YOUR WORK BELOW 👇
@@ -210,6 +246,11 @@ function get3rdCar(inventory) {
* it will return `This is a Lincoln Navigator`.
*/
function getCarInfoByIndex(inventory, index) {
+ for(let i = 0; i<= inventory.length-1;i++){
+ if(i === index){
+ return `This is a ${inventory[i].car_make} ${inventory[i].car_model}`;
+ }
+ }
/* code here */
}
@@ -224,8 +265,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) {
+ //first way
+ let lastCar = inventory[inventory.length-1];
+ return `This is a ${lastCar.car_make} ${lastCar.car_model}`;
}
/**
@@ -237,8 +280,13 @@ 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 carModel = [];
+ for(let i = 0;i<=inventory.length-1;i++){
+ carModel.push(inventory[i].car_year);
+ // return carModel;
+ }
+ return carModel;
}
/**
@@ -255,8 +303,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 , carId) {
+ function getCarInfoById(inventory , Id) {
+ for(let i=0; i <= inventory.length-1;i++){
+ //if -1 is not used the arr starts at 0 so it will cause error
+ if(i === (Id-1)){
+ return `This is a ${inventory[i].car_make} ${inventory[i].car_model}`;
+ }
+ }
}
/**
@@ -273,8 +327,23 @@ 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 ,maxYear) {
+ let foundOld = [];
+ //tested it from last to first
+ // for(let i=inventory.leng; i>=0; i--){
+ // if(maxYear >= inventory[i].car_year){
+ // foundOld.push(inventory[i]);
+ // }
+ // }
+ // return foundOld;
+
+ for(let i=0; i<=inventory.length-1; i++){
+ if(maxYear >= inventory[i].car_year){
+ foundOld.push(inventory[i]);
+ }
+ }
+ return foundOld;
+
}
/**
@@ -290,8 +359,36 @@ 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 */
+/*
+// ⭐️ Example Test Data ⭐️
+
+var inventory = [
+ { id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 },
+ { id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 },
+ { id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 },
+ { id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 },
+ { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 },
+ { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 },
+ { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 },
+ { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 },
+ { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 },
+ { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 },
+ { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 },
+ { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 },
+ { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 },
+ { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 }
+ /// ... Truncated
+]
+*/
+
+function getGermanCars(inventory) {
+ let gerCar = [];
+ for(let i=0; i<= inventory.length-1;i++){
+ if(inventory[i].car_make === 'Audi' || inventory[i].car_make === 'Mercedes-Benz' || inventory[i].car_make === 'Volkswagen' || inventory[i].car_make === 'BMW' ){
+ gerCar.push(inventory[i]);
+ }
+ }
+ return gerCar;
}
/**
@@ -307,8 +404,21 @@ 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(odometerNum) {
+ // let x , y;
+ // y = {
+ // odometer: odometerNum, drive:function(distance){
+ // x = (this.odometer+=distance);
+ // return x;
+ // }
+ // };
+ // return y;
+ return{
+ odometer:odometerNum , drive: function(distance){
+ return (this.odometer += distance);
+ }
+ };
+
}
/// ////// END OF CHALLENGE /////////