Skip to content
Open

done #10

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
50 changes: 50 additions & 0 deletions answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//1
function sum(x,y,z){
return (x+y+z);
};


//2
function colorCar (color){
return `${color} car`;
};

//3
function printObj(obj){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your function is well-written, but the question also asks you to create a sample object.

for( prop in obj){
console.log(prop +" is "+obj[prop]);
}
}

//4
function vehicleType(color,code){
if(code == 1)
return `a ${color} car`;
if(code == 2)
return `a ${color} motorbike `;
};

//5 c
console.log((3 === 3) ? "yes" : "no");

//6
function vehicle(color,code,age){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You haven't used your age parameter here. What if I wanted to print out a new vehicle?

if(code == 1)
return `a ${color} used car`;
if(code == 2)
return `a ${color} used motorbike `;
};

//7
let vehicles = ["motorbike","caravan","bike","suv"];

//8
vehicles[2];
//
function vehicleType2(color,code,age){
if(age > 1)
return `a ${color} used ${vehicles[code]}`;

return `a ${color} new ${vehicles[code]}`;
};

16 changes: 12 additions & 4 deletions ex.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// TODO: define addFavoriteBook(..) function

// TODO: define printFavoriteBooks() function
function addFavoriteBook(bookName){
if(!bookName.includes("Great"))
favoriteBooks.push(bookName);
}

const favoriteBooks = [];

addFavoriteBook("A Song of Ice and Fire");
addFavoriteBook("The Great Gatsby");
addFavoriteBook("Crime & Punishment");
addFavoriteBook("Great Expectations");
addFavoriteBook("You Don't Know JS");

// TODO: print out favorite books

function printFavoriteBooks(){
for(let i = 0; i<favoriteBooks.length; i++){
console.log(`Your ${favoriteBooks.length } favorite books are : ${i+1}. ${favoriteBooks[i]}`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really an issue, but I would just print out Your ${favoriteBooks.length } favorite books are once at the beginning instead of inside the loop because this message is more like a title instead of something that should be repeated for each line.

}
}

printFavoriteBooks();