-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPrototypes2.js
More file actions
83 lines (39 loc) · 1.3 KB
/
Copy pathPrototypes2.js
File metadata and controls
83 lines (39 loc) · 1.3 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function Book(title,author,ISBN){
this.title = title;
this.author = author;
this.ISBN = ISBN;
this.isAvailable = true;
}
Book.prototype.checkAvailability = function(){
return this.isAvailable ? `${this.title} is not available` : `${this.title} is available `
}
Book.prototype.checkBook = function (){
if(this.isAvailable){
this.isAvailable = false;
return `You have borrowed "${this.title}" is currently borrowed`;
}else{
return `Sorry, "${this.title}" is already borrowed`
}
}
Book.prototype.returnBook = function(){
if(!this.isAvailable){
this.isAvailable = true;
return `You have returned "${this.title}"`
}else{
return `"${this.title}" was not borrowed`;
}
}
function Library(name){
this.name = name;
this.books = [];
}
Library.prototype.addBook = function(book){
this.books.push(book)
}
Library.prototype.listBooks = function(){
const book = this.books.map(book=>book.title.toLowerCase() == title.toLowerCase());
return book ? book.checkAvailability() : `Book titled "${title}" not found in the library`;
}
const cityLibrary = new Library("City Library");
const book1 = new Book("The Great GatsBy","D. Dennis Peter","er3e7823238");
console.log(cityLibrary.addBook(book1))