Skip to content

Robel mengistu #114

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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<!-- Testing the commit-->
<title>Exercises</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
166 changes: 138 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -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');




/**
Expand All @@ -95,8 +111,13 @@ function temperatureInF(/* code here */) {
* email: "[email protected]",
* }
*/
function makePersonObject(/* code here */) {
/* code here */
function makePersonObject(id, name, email) {
let madeObj ={
id:id,
name:name,
email:email
};
return madeObj;
}

/**
Expand All @@ -112,8 +133,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({ name }) {
return `Hello, my name is ${name}` ;
}


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

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


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

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

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

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

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

}

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

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