From 4eb807141d901ffc054bbdce6707dd1b523bfe92 Mon Sep 17 00:00:00 2001 From: terratamo Date: Sun, 1 Sep 2019 12:27:25 -0400 Subject: [PATCH] hw7 --- answer.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ex.js | 37 ++++++++++++++++++++++---------- 2 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 answer.js diff --git a/answer.js b/answer.js new file mode 100644 index 0000000..3e56bfa --- /dev/null +++ b/answer.js @@ -0,0 +1,64 @@ +//1 + +function flowersabc (a, b, c){ + console.log(a + b + c); +} + +flowersabc(3, 5 ,7 ); + +//2 + +function colorCar(color){ + console.log("a " + color + " car") +} + +colorCar("blue"); + +//3 + +let canada = { + + people: "kind", + economy: "not bad not good", + numberOfProvience: 13 +}; + +function myFunction() { + console.log(canada); + +} +myFunction(); + +//4 + +function vehicleType(color, code){ + if (code===1){ + console.log("a " + color+ " motorbike"); + }else{ + console.log(code +" " + color + " car") + } +} + +vehicleType("yellow",3); + +//5 + +console.log(3 === 3? "yes" : "no") + +//6//7//8//9 + +let vehicleList=["atv","motorbike", "caravan", "bike", ] + +function vehicle(color, code, age){ + + const vehicleCode=vehicleList[code]; + + if(age>1 ){ + console.log("a" + color + " used " + vehicleCode ) + }else{ + console.log("a" +" " + color + " new " + vehicleCode ) + } +} +vehicle("green", 1, 3); + + diff --git a/ex.js b/ex.js index d2f433d..96c8ae8 100644 --- a/ex.js +++ b/ex.js @@ -1,13 +1,28 @@ // TODO: define addFavoriteBook(..) function -// TODO: define printFavoriteBooks() function - -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 addFavoriteBook(bookName) { + if (!bookName.includes('Great')) { + favoriteBooks.push(bookName); + } + } + + // TODO: define printFavoriteBooks() function + + function printFavoriteBooks() { + console.log('Favorite Books: ' + favoriteBooks.length); + for (const index of favoriteBooks) { + console.log(index); + } + } + + 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 + + printFavoriteBooks(); \ No newline at end of file