-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (56 loc) · 2.05 KB
/
index.js
File metadata and controls
62 lines (56 loc) · 2.05 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
import { DateTime } from './luxon.js';
import Book from './modules/Book.js';
import displayBooks from './modules/displayBooks.js';
const books = new Book();
displayBooks();
const button = document.getElementById('add');
button.addEventListener('click', () => {
const title = document.getElementById('title');
const author = document.getElementById('author');
const message = document.getElementById('error-message');
message.textContent = '';
if (title.value === '' || author.value === '') {
message.textContent = 'Please fill both the title and the author before adding.';
} else if (!books.search(title.value, author.value)) {
books.add(title.value, author.value);
displayBooks();
title.value = '';
author.value = '';
message.textContent = 'The book has been added successfully.';
message.style.color = 'green';
} else {
const message = document.getElementById('error-message');
message.textContent = 'The book has already been added.';
}
setInterval(() => {
message.textContent = ' ';
}, 1000);
});
const booksSection = document.getElementById('books');
const addSection = document.getElementById('add-book');
const contactSection = document.getElementById('contact');
document.getElementById('menu-list').addEventListener('click', () => {
booksSection.style.display = 'flex';
addSection.style.display = 'none';
contactSection.style.display = 'none';
});
document.getElementById('menu-add-book').addEventListener('click', () => {
booksSection.style.display = 'none';
addSection.style.display = 'flex';
contactSection.style.display = 'none';
});
document.getElementById('menu-contact').addEventListener('click', () => {
booksSection.style.display = 'none';
addSection.style.display = 'none';
contactSection.style.display = 'flex';
});
const dateContainer = document.getElementById('date-time');
const myTimer = () => {
const today = DateTime.now();
const time = today.toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS);
dateContainer.textContent = time;
};
myTimer();
setInterval(() => {
myTimer();
}, 1000);