You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
class Book {
|
|
constructor(title, pages) {
|
|
this.title = title;
|
|
this.pages = pages;
|
|
}
|
|
|
|
displayPage(pageIndex) {
|
|
var page = this.pages[pageIndex];
|
|
|
|
document.getElementById("title").innerHTML = this.title;
|
|
document.getElementById("pageImage").src = page.imageSRC;
|
|
document.getElementById("pageText").innerHTML = page.text;
|
|
|
|
var buttons = document.getElementById("buttons");
|
|
|
|
// clear buttons
|
|
buttons.innerHTML = "";
|
|
|
|
for(var button of page.buttons) {
|
|
const btn = document.createElement("button");
|
|
btn.append(document.createTextNode(button.text));
|
|
btn.setAttribute("onclick", "book.displayPage("+ button.pageIndex +")");
|
|
buttons.append(btn);
|
|
}
|
|
}
|
|
}
|
|
|
|
class Page {
|
|
constructor(imageSRC, text, butttons) {
|
|
this.imageSRC = imageSRC;
|
|
this.text = text;
|
|
this.buttons = buttons;
|
|
}
|
|
};
|
|
|
|
class Button {
|
|
constructor(pageIndex, text) {
|
|
this.pageIndex = pageIndex;
|
|
this.text = text;
|
|
}
|
|
}
|
|
|