diff --git a/books.json b/books.json index e69de29..0c67c88 100644 --- a/books.json +++ b/books.json @@ -0,0 +1,25 @@ +{ + "Journal": { + "title": "Jatuh Bangung Seorang Fullstack", + "author": "Kang Udin", + "_totalPages": 89, + "readingDays": 1, + "isAvail": true + }, + "Biography": { + "title": "Orang Dibalik Apple", + "author": "Mas Bejo", + "_totalPages": 327, + "readingDays": 4, + "isAvail": true, + "figure": "Steve Wozniak" + }, + "History": { + "title": "Awal Peradaban Callback", + "author": "Bang Togar", + "_totalPages": 127, + "readingDays": 2, + "isAvail": true, + "century": "Middle Earth" + } +} \ No newline at end of file diff --git a/perpus.js b/perpus.js new file mode 100644 index 0000000..4428131 --- /dev/null +++ b/perpus.js @@ -0,0 +1,60 @@ +class Perpus { + getBook() { + let fs = require('fs'); + + this.book = fs.readFileSync('books.json', 'UTF-8'); + } +} + +class Journal { + getData() { + let fs = require('fs'); + let data = fs.readFileSync('books.json', 'UTF-8'); + data = JSON.parse(data); + + this.title = data.Journal.title; + this.author = data.Journal.author; + this.totalPages = (data.Journal._totalPages > 200 ? 'Banyak halamannya capek ngitungnya' : data.Journal._totalPages); + this.readingDays = data.Journal.readingDays; + } +} + +class Biography { + getData() { + let fs = require('fs'); + let data = fs.readFileSync('books.json', 'UTF-8'); + data = JSON.parse(data); + + this.title = data.Biography.title; + this.author = data.Biography.author; + this.totalPages = (data.Biography._totalPages > 200 ? 'Banyak halamannya capek ngitungnya' : data.Biography._totalPages); + this.readingDays = data.Biography.readingDays; + this.figure = data.Biography.figure; + } +} + +class History { + getData() { + let fs = require('fs'); + let data = fs.readFileSync('books.json', 'UTF-8'); + data = JSON.parse(data); + + this.title = data.History.title; + this.author = data.History.author; + this.totalPages = (data.History._totalPages > 200 ? 'Banyak halamannya capek ngitungnya' : data.History._totalPages); + this.readingDays = data.History.readingDays; + this.century = data.History.century; + } +} + +let perpustakaan = new Perpus(); +let journal = new Journal(); +let biography = new Biography(); +let history = new History(); +journal.getData(); +biography.getData(); +history.getData(); +console.log(biography.title) +console.log(biography.author) +console.log(biography.totalPages) +console.log(biography.readingDays)