-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution127.js
29 lines (24 loc) · 1007 Bytes
/
solution127.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Building upon the previous day's code practice
//define a addFavoriteBook function that receives a single param called 'bookName'
function addFavoriteBook (bookName) {
//if the provided 'bookName' string does NOT have the word Great in it, add it to the favoriteBooks array.
if (!bookName.includes('Great')) {
favoriteBooks.push(bookName);
}
}
//define a printFavoriteBooks() function that receives no parameters
function printFavoriteBooks() {
console.log (`Favorite Books: ${favoriteBooks.length}` );
// prinFavoriteBooks should loop thru favoriteBooks array and print out each value.
for (let bookName of favoriteBooks) {
console.log(bookName);
}
}
let favoriteBooks = [];
addFavoriteBook('A Song of Ice and Fire')
addFavoriteBook('The Great Gatsby');
addFavoriteBook('Crime & Punishment');
addFavoriteBook('Great Expectations');
addFavoriteBook('You Don"t Know JS');
addFavoriteBook('Eloquent Javascript');
printFavoriteBooks();