Skip to content
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
80 changes: 80 additions & 0 deletions answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 1.answer

var p1 = 6;
var p2 = 7;
var p3 = 10;
function tripleFunction (p1,p2,p3) {
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.

Good work!

return p1 + p2 + p3
}

tripleFunction(p1,p2,p3);

// 2.answer

function colorCar(color){
console.log( 'a' +''+ color +''+ 'car');
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.

This is good but the output doesn't have spaces. If you want to put spaces, you need to use a space in your string ' ' instead of ''.

}

colorCar("red");

//3.answer

const aboutMe ={
name : 'Elif',
surname : 'Yasar',
age: '19',
nationality: 'Turkish',
address: {
street: 'Hello Street',
city: 'Toronto'
},
}

function learnAboutMe(){
console.log(aboutMe);
}

learnAboutMe();

// 4.answer

function vehcileType(color,code){
if (code === 1){
console.log('a'+ color + 'car')
}
else {
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.

Motorbike should only print out if the code is 2. What will this function print out if you call it with values other than 1 or 2?

console.log('a'+ color + 'motorbike')
}
}
vehcileType('blue', 1);

//5.answer

console.log(3 === 3 ? 'yes' : 'no');

//6.answer

let code = ["car" , "motorbike"]
function vehicle(color,age,code){
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.

I think you combined questions 6 and 9 but that's okay!
Question 9 involves writing a function with three parameters, color, age, and code. code should be a number (array index) that you use to get the value from an array. It shouldn't be the actual element from the array.
For example, you are calling your function like this:

vehicle("blue", 3 , code[0]); // the third parameter, code[0], is the string "car" from your array on line 57

The function should be called like this:

vehicle("blue", 3, 0); // the third parameter is a number (array index)

Then in the function, you should use the array index to get the vehicle type from the array.


if (age <= 1){
console.log('a'+ color + 'new' + code);
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.

make sure your output has spaces so it's easily readable! You can add spaces like this:

console.log('a '+ color + ' new ' + code);

}else if(age >1){
console.log('a'+''+ color +''+ 'used' +''+ code);
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.

Same comment as above regarding spaces. You should use ' ' to add a space instead of ''.

}

}
vehicle("blue", 3 , code[0] )


//7.answer

let listOfVehicles = ["motorbike", "caravan", "bike", "car","ship", "plane",]


//8.answer
console.log(listOfVehicles[2]);

//9.answer

vehicle("green",1,listOfVehicles[2]);
19 changes: 17 additions & 2 deletions ex.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// TODO: define addFavoriteBook(..) function

// TODO: define printFavoriteBooks() function

const favoriteBooks = [];

addFavoriteBook("A Song of Ice and Fire");
Expand All @@ -10,4 +8,21 @@ addFavoriteBook("Crime & Punishment");
addFavoriteBook("Great Expectations");
addFavoriteBook("You Don't Know JS");

function addFavoriteBook(bookName) {
if (!bookName.includes('Great')){
favoriteBooks.push(bookName);
}
}
console.log(favoriteBooks);

// TODO: define printFavoriteBooks() function

function printFavoriteBooks(){
console.log('There are' + favoriteBooks.length + 'favorite books.');
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.

Well done! Just make sure to add spaces in your output. 😄

for (let favbooks of favoriteBooks){
console.log(favbooks);
}
}

// TODO: print out favorite books
printFavoriteBooks(favoriteBooks);