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
57 changes: 57 additions & 0 deletions answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//Question 1
function sumOfThree (num1,num2,num3) {
return num1+num2+num3
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 job!

}

//Question 2
function colorCar(x) {
return `a ${x} car`
}

//Question 3
let person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}

function objectPrinter(person) {
return (person)
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 can also use a for...of loop to print out the properties and values from this object.
See here

}

//Question 4
function vehicleType (color,code) {
if (code == 1) {
return `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.

This function should print out motorbike only if code is 2. What if I called the function like this: vehicleType('blue', 3)?

return `a ${color} motorbike`
}
}

//Question 5
let result = 3===3? "yes" : "No"
console.log(result)

//Question 6
function vehicle (color,code,age) {
if (code == 1 && age>0) {
return `a ${color} used car`
} else if(code ==2 && age>0) {
return `a ${color} used motorbike`
}else if(code ==1 && age==0) {
return `a ${color} new 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.

Similar comment to above - if I call this function with a code that is not 2 or 1, the output will be motorbike, but that's not the expected output.

return `a ${color} new motorbike`
}
}

//Question 7
listOfVehicles = ["motorbike", "caravan", "bike"]
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 to use const or let to declare the variable.


//QUestion 8
console.log(listOfVehicles[2])

//Question 9
function vehicleType (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.

Nice work!

if (age > 0) {
return `a ${color} used ${listOfVehicles[code]}`
} else {
return `a ${color} new ${listOfVehicles[code]}`
}
}
18 changes: 15 additions & 3 deletions ex.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
// TODO: define addFavoriteBook(..) function
const favoriteBooks = [];

function addFavoriteBook (bookName) {
if (bookName.includes("Great")!== true) {
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.

Can you think of a shorter way to write this condition without having to use !== true?

favoriteBooks.push(bookName)
}
}

// TODO: define printFavoriteBooks() function

const favoriteBooks = [];
function printFavoriteBooks() {
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.

Right now, your function is only printing out the number of books, but it should also print out what's in the favoriteBooks array.

The for loop that you wrote on line 21 should also be included in the printFavoriteBooks function.

console.log(`Favorite Books: ${favoriteBooks.length}`)
}

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
printFavoriteBooks()

for (let i of favoriteBooks) {
console.log(i)
}