From 1cc85a0c3ce93b761a41c9a5d74ffa95f2fabd2f Mon Sep 17 00:00:00 2001 From: fahrizalrahman Date: Sat, 7 Apr 2018 17:48:10 +0700 Subject: [PATCH] Tugas Ujian 2 --- perpustakaan.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 perpustakaan.js diff --git a/perpustakaan.js b/perpustakaan.js new file mode 100644 index 0000000..e6e2c68 --- /dev/null +++ b/perpustakaan.js @@ -0,0 +1,83 @@ +function Journal(obj) { + this.title = obj.title; + this.author = obj.author; + this._totalPages = obj._totalPages; + this.readingDays = obj.readingDays; + this.isAvail = true; +} + +function Biography(obj) { + this.title = obj.title; + this.author = obj.author; + this._totalPages = obj._totalPages; + this.readingDays = obj.readingDays; + this.figure = obj.figure; + this.isAvail = true; +} + +function History(obj) { + this.title = obj.title; + this.author = obj.author; + this._totalPages = obj._totalPages; + this.readingDays = obj.readingDays; + this.century = obj.century; + this.isAvail = true; +} + +function dataBuku(){ + this.arrayOfBook = []; +} + +dataBuku.prototype = { + save:function(personBook){ + this.arrayOfBook.push(personBook); + }, + getAll:function(){ + return this.arrayOfBook; + } +}; + + + +Journal.prototype.toString = function(){ + return "["+this.title+"] author: " + this.author + ", _totalPages: " + this._totalPages + ", readingDays: " + this.readingDays+ ", figure: " + this.figure+ ", isAvail: " + this.isAvail + ", century: " + this.century; +}; + +Biography.prototype.toString = function(){ + return "["+this.title+"] author: " + this.author + ", _totalPages: " + this._totalPages + ", readingDays: " + this.readingDays+ ", figure: " + this.figure+ ", isAvail: " + this.isAvail + ", century: " + this.century; +}; + +History.prototype.toString = function(){ + return "["+this.title+"] author: " + this.author + ", _totalPages: " + this._totalPages + ", readingDays: " + this.readingDays+ ", figure: " + this.figure+ ", isAvail: " + this.isAvail + ", century: " + this.century; +}; + +var Journal = new Journal({ + title: "Jatuh Bangung Seorang Fullstack", + author: "Kang Udin", + _totalPages: 89, + readingDays: Math.ceil(89 / 100), +}); + +var Biography = new Biography({ + title: "Orang Dibalik Apple", + author: "Mas Bejo", + _totalPages: 327, + readingDays: Math.ceil(327 / 100), + figure : "Steve Wozniak", +}); + +var History = new History({ + title: "Awal Peradaban Callback", + author: "Bang Togar", + _totalPages: 127, + readingDays: Math.ceil(127 / 100), + century : "Middle Earth", +}); + + +var buku = new dataBuku(); +buku.save(Journal); +buku.save(Biography); +buku.save(History); + +console.log(buku.getAll());