From cb11d3d5dcbab4b6175df1ef3d89e739546b4e69 Mon Sep 17 00:00:00 2001 From: Riko Pernando Date: Sat, 7 Apr 2018 17:47:14 +0700 Subject: [PATCH 1/2] ujian phase 2 ujian phase 2 --- books.json | 25 +++++++++++ soalUjian.js | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 soalUjian.js 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..4970cf5 --- /dev/null +++ b/soalUjian.js @@ -0,0 +1,118 @@ +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) + +'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 newbook = JSON.parse(rawData) +console.log(newbook) + + + + + + + + + + + + From 53fdff34faf258c174c9021825083ba19b9f613c Mon Sep 17 00:00:00 2001 From: Riko Pernando Date: Sat, 7 Apr 2018 17:47:53 +0700 Subject: [PATCH 2/2] commit lagi commit lagi --- soalUjian.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/soalUjian.js b/soalUjian.js index 4970cf5..4b76627 100644 --- a/soalUjian.js +++ b/soalUjian.js @@ -91,6 +91,8 @@ var perpus = new perpustakaan( 'Perpustakaan Javascript', 'Pondok Indah', book) +console.log(perpus.book) + 'use strict'; const fs = require('fs') @@ -101,9 +103,9 @@ let data = JSON.stringify(perpus.book, null, 2); fs.writeFileSync('books.json', data); -let rawData = fs.readFileSync('books.json') -let newbook = JSON.parse(rawData) -console.log(newbook) +// let rawData = fs.readFileSync('books.json') +// let book = JSON.parse(rawData) +// console.log(book)