-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookReader.js
More file actions
41 lines (38 loc) · 960 Bytes
/
BookReader.js
File metadata and controls
41 lines (38 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Book{
constructor(author,genre){
this.author = author;
this.genre = genre;
}
}
class BookReader{
constructor(){
this.currentBook = null;
this.books = {};
}
add(title,Author,Genre){
if (this.books[title] === undefined){
this.books[title] = new Book(Author,Genre);
} else {
console.log('This book is already in the system');
}
}
remove(title){
if (this.books[title]){
delete this.books[title];
} else {
console.log('This book is not inside of the system');
}
}
find(title){
return this.books[title];
}
open(title){
if(this.books[title]){
this.currentBook = this.books[title];
}
}
}
var bookReader = new BookReader();
bookReader.add('Harry Potter','J.K. Rowling','Realistic');
bookReader.add('To Kill a Mockingbird','Harper Lee','Literature');
console.log(bookReader);