-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathass7.html
More file actions
107 lines (84 loc) · 2.97 KB
/
ass7.html
File metadata and controls
107 lines (84 loc) · 2.97 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head>
<title>Objects</title>
</head>
<body>
<script>
const book1={
title:'The Courage to Be Disliked',
author:'Ichiro Kishimi and Fumitake Koga',
ISBN:'978-1501197277',
isBorrowed:false,
borrow(){
this.isBorrowed=true;
return `The book borrowed:${this.title}`;
},
returnBook(){
this.isBorrowed=false;
return `The book returned:${this.title}`;
}
};
const book2 = {
title:'Kingdom of Ash',
author:'Sarah J. Maas',
ISBN:'978-1681195773',
isBorrowed:false,
borrow(){
this.isBorrowed=true;
},
returnBook(){
this.isBorrowed=false;
}
};
const book3={
title:'Powerless',
author:'Lauren Roberts',
ISBN:'978-1665935590',
isBorrowed:false,
borrow(){
this.isBorrowed=true;
},
returnBook(){
this.isBorrowed=false;
}
};
const library={
books:[book1,book2,book3],
addBook(book){
this.books.push(book);
},
findBookByISBN(isbn){
for (let book of this.books){
if (book.ISBN === isbn){
return book;
}
}
return null;
},
listAvailableBooks() {
this.books.forEach(book => {
if (!book.isBorrowed){
console.log(book.title);
}
});
},
listBorrowedBooks(){
this.books.forEach(book => {
if (book.isBorrowed){
console.log(book.title);
}
});
}
};
console.log("All available books:");
library.listAvailableBooks();
console.log("Borrowing 'Powerless'...");
library.findBookByISBN('978-1665935590').borrow();
console.log("Available books after borrowing:");
library.listAvailableBooks();
console.log("Borrowed books:");
library.listBorrowedBooks();
</script>
</body>
</html>