From fe19486898e46fee827dda71942f3cfa2e10801f Mon Sep 17 00:00:00 2001 From: kursadc Date: Sun, 1 Sep 2019 18:10:10 -0400 Subject: [PATCH] week7 submission --- answer.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ex.js | 18 +++++++++++++++--- 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 answer.js diff --git a/answer.js b/answer.js new file mode 100644 index 0000000..469608e --- /dev/null +++ b/answer.js @@ -0,0 +1,57 @@ +//Question 1 +function sumOfThree (num1,num2,num3) { + return num1+num2+num3 + } + +//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) +} + +//Question 4 +function vehicleType (color,code) { + if (code == 1) { + return `a ${color} car` + } else { + 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 { + return `a ${color} new motorbike` + } +} + +//Question 7 +listOfVehicles = ["motorbike", "caravan", "bike"] + +//QUestion 8 +console.log(listOfVehicles[2]) + +//Question 9 +function vehicleType (color,code,age) { + if (age > 0) { + return `a ${color} used ${listOfVehicles[code]}` + } else { + return `a ${color} new ${listOfVehicles[code]}` + } + } \ No newline at end of file diff --git a/ex.js b/ex.js index d2f433d..52f03bb 100644 --- a/ex.js +++ b/ex.js @@ -1,8 +1,16 @@ -// TODO: define addFavoriteBook(..) function +const favoriteBooks = []; + +function addFavoriteBook (bookName) { + if (bookName.includes("Great")!== true) { + favoriteBooks.push(bookName) + } +} // TODO: define printFavoriteBooks() function -const favoriteBooks = []; +function printFavoriteBooks() { + console.log(`Favorite Books: ${favoriteBooks.length}`) +} addFavoriteBook("A Song of Ice and Fire"); addFavoriteBook("The Great Gatsby"); @@ -10,4 +18,8 @@ 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) +}