From afb6cf6af855e2c60d2f7ec66bd1fb3896f77cb5 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Sep 2019 13:53:15 -0400 Subject: [PATCH] completed --- answer.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ ex.js | 16 ++++++++++++---- 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 answer.js diff --git a/answer.js b/answer.js new file mode 100644 index 0000000..c856c2e --- /dev/null +++ b/answer.js @@ -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){ + 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){ + 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]}`; +}; + diff --git a/ex.js b/ex.js index d2f433d..3264164 100644 --- a/ex.js +++ b/ex.js @@ -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