From 53b6d531d7c6762f15ab24a4b66c5d56dc569014 Mon Sep 17 00:00:00 2001 From: esyasar Date: Wed, 4 Sep 2019 03:54:02 -0400 Subject: [PATCH] week 7 hw --- answer.js | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ex.js | 19 +++++++++++-- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 answer.js diff --git a/answer.js b/answer.js new file mode 100644 index 0000000..1842313 --- /dev/null +++ b/answer.js @@ -0,0 +1,80 @@ +// 1.answer + +var p1 = 6; +var p2 = 7; +var p3 = 10; + function tripleFunction (p1,p2,p3) { + return p1 + p2 + p3 + } + +tripleFunction(p1,p2,p3); + +// 2.answer + +function colorCar(color){ + console.log( 'a' +''+ color +''+ 'car'); +} + +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 { + 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){ + + if (age <= 1){ + console.log('a'+ color + 'new' + code); + }else if(age >1){ + console.log('a'+''+ color +''+ 'used' +''+ code); + } + + } + 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]); diff --git a/ex.js b/ex.js index d2f433d..e46c2b1 100644 --- a/ex.js +++ b/ex.js @@ -1,7 +1,5 @@ // TODO: define addFavoriteBook(..) function -// TODO: define printFavoriteBooks() function - const favoriteBooks = []; addFavoriteBook("A Song of Ice and Fire"); @@ -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.'); + for (let favbooks of favoriteBooks){ + console.log(favbooks); + } +} + // TODO: print out favorite books +printFavoriteBooks(favoriteBooks);