-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_2.js
49 lines (41 loc) · 948 Bytes
/
ex_2.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Bookshelf {
constructor() {
this.favoriteBooks = [];
}
addFavoriteBook(bookName){
if (!bookName.includes("Great")) {
this.favoriteBooks.push(bookName);
}
}
printFavoriteBooks(){
console.log(`Favorite Books: ${String(this.favoriteBooks.length)}`);
for (let bookName of this.favoriteBooks) {
console.log(bookName);
}
}
}
function loadBooks(books1) {
// TODO: call fakeAjax( .. );
fakeAjax(BOOK_API, function addingBooks(bookData){
for(let book of bookData){
books1.addFavoriteBook(book);
}
books1.printFavoriteBooks();
});
}
var BOOK_API = "https://some.url/api";
// ***********************
// NOTE: don't modify this function at all
function fakeAjax(url,cb) {
setTimeout(function fakeLoadingDelay(){
cb([
"A Song of Ice and Fire",
"The Great Gatsby",
"Crime & Punishment",
"Great Expectations",
"You Don't Know JS"
]);
},500);
}
var books1 = new Bookshelf();
loadBooks(books1);