A promise

Run Settings
LanguageJavaScript
Language Version
Run Command
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); } } } let myShelf= new Bookshelf(); loadBooks(myShelf); var BOOK_API = "https://some.url/api"; async function loadBooks(bookshelf) { try { const bookNames = await new Promise((resolve, reject) => { fakeAjax(BOOK_API,resolve); }); for (let bookName of bookNames) { bookshelf.addFavoriteBook(bookName); } bookshelf.printFavoriteBooks(); } catch (error) { console.error(error); } } // *********************** // 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" ]); },100); }
Editor Settings
Theme
Key bindings
Full width
Lines