diff --git a/books.json b/books.json index e69de29..1de2a3a 100644 --- a/books.json +++ b/books.json @@ -0,0 +1,25 @@ +[ + { + "title": "Jatuh Bangung Seorang Fullstack", + "author": "Kang Udin", + "_totalPage": 89, + "_readingDays": 0, + "isAvail": true + }, + { + "title": "Orang Dibalik Apple", + "author": "Mas Bejo", + "_totalPage": 327, + "figure": "Steve Wozniak", + "_readingDays": 0, + "isAvail": true + }, + { + "title": "Awal Peradaban Callback", + "author": "Bang Togar", + "_totalPage": 127, + "figure": "Middle Earth", + "_readingDays": 0, + "isAvail": true + } +] \ No newline at end of file diff --git a/soalUjian.js b/soalUjian.js new file mode 100644 index 0000000..4b76627 --- /dev/null +++ b/soalUjian.js @@ -0,0 +1,120 @@ +class Journal{ + constructor(title,author,totalPage){ + this.title = title + this.author = author + this._totalPage = totalPage + this._readingDays = 0 + this.isAvail = true + } + get totalPage () { + if (this._totalPage > 200) { + return `Banyak halamannya capek ngitungnya` + }else{ + return this._totalPage + } + } + set readingDays(readingDays){ + this.readingDays = Math.ceil(this._totalPage / 100) + } + + +} +class Biography{ + constructor(title,author,totalPage,figure){ + this.title = title + this.author = author + this._totalPage = totalPage + this.figure = figure + this._readingDays = 0 + this.isAvail = true + } + get totalPage () { + if (this._totalPage > 200) { + return `Banyak halamannya capek ngitungnya` + }else{ + return this._totalPage + } + } + set readingDays(readingDays){ + this.readingDays = Math.ceil(this._totalPage / 100) + } +} +class History{ + constructor(title,author,totalPage,figure){ + this.title = title + this.author = author + this._totalPage = totalPage + this.figure = figure + this._readingDays = 0 + this.isAvail = true + } + get totalPage () { + if (this._totalPage > 200) { + return `Banyak halamannya capek ngitungnya` + }else{ + return this._totalPage + } + } + set readingDays(readingDays){ + this.readingDays = Math.ceil(this._totalPage / 100) + } + +} + +class perpustakaan { + constructor(nama,alamat,book){ + this.nama = nama + this.alamat = alamat + this.book = book + } +} +var newJurnal = new Journal( + 'Jatuh Bangung Seorang Fullstack', + 'Kang Udin', + 89) + +var newBiography = new Biography( + 'Orang Dibalik Apple', + 'Mas Bejo', + 327, + 'Steve Wozniak') + +var newHistory = new History( + 'Awal Peradaban Callback', + 'Bang Togar', + 127, + 'Middle Earth') + +let book = [newJurnal,newBiography,newHistory] + +var perpus = new perpustakaan( + 'Perpustakaan Javascript', + 'Pondok Indah', book) + +console.log(perpus.book) + +'use strict'; + +const fs = require('fs') + + + +let data = JSON.stringify(perpus.book, null, 2); +fs.writeFileSync('books.json', data); + + +// let rawData = fs.readFileSync('books.json') +// let book = JSON.parse(rawData) +// console.log(book) + + + + + + + + + + + +