-
Notifications
You must be signed in to change notification settings - Fork 0
/
Central Library teacher 2.js
73 lines (63 loc) · 2.07 KB
/
Central Library teacher 2.js
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
class Library {
constructor(bookList) {
this.bookList = bookList;
this.issuedBooks = {};
}
getBookList() {
this.bookList.forEach(element => {
console.log(element);
return element;
});
}
issueBook(bookname, user) {
if (this.issuedBooks[bookname] == undefined) {
this.issuedBooks[bookname] = user;
}
else {
console.log("This book is already issued!");
}
}
returnBook(bookname) {
delete this.issuedBooks[bookname];
}
}
let LibraryObj = new Library(["B.S.Grewal", "Erwin Kreysig", "Mechanical Engineering", "Boylested", "EVS", "N.D. Bhatt", "A.P. French", "Chemistry", "Electrical Engineering"])
//console.log(LibraryObj.getBookList()) undefined
//let booklist=document.getElementById("booklist-el")
//booklist.textContent+= LibraryObj.getBookList()
//console.log(LibraryObj.issueBook("B.S.Grewal","Hrishita Paul"))
let Submit = document.getElementById("submit-el")
Submit.addEventListener("click", function (e) {
let FirstBook = document.getElementById("FirstBook-el")
let SecondBook = document.getElementById("SecondBook-el")
let ThirdBook = document.getElementById("ThirdBook-el")
let FourthBook = document.getElementById("FourthBook-el")
let output = document.getElementById("output-el")
let array = []
if (FirstBook.checked) {
array.push(FirstBook.value)
}
if (SecondBook.checked) {
array.push(SecondBook.value)
}
if (ThirdBook.checked) {
array.push(ThirdBook.value)
}
if (FourthBook.checked) {
array.push(FourthBook.value)
}
//console.log("Submit button has been clicked")
console.log(array.length)
if (array.length === 1) {
output.textContent = "Can issue 1 book"
}
else if (array.length === 2) {
output.textContent = "Can issue 2 books"
}
else if (array.length === 3) {
output.textContent = "Can issue 3 books"
}
else if (array.length === 4) {
output.textContent = "Can issue 4 books"
}
})