Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const divElem = document.querySelector('#container');
- let [name, hall, ticketPrice, addBtn] = Array.from(divElem.children);
- let movieSection = document.querySelector('#movies>ul');
- let archiveSection = document.querySelector('#archive>ul');
- let clearBtn = document.querySelector('#archive>button');
- addBtn.addEventListener('click', addMovie);
- function addMovie(e) {
- e.preventDefault();
- let nameVal = name.value;
- let hallVal = hall.value;
- let ticketVal = Number(ticketPrice.value);
- let archiveBtn = el('button', 'Archive')
- let input = el('input', '', { placeholder: 'Tickets Sold' })
- if (nameVal && hallVal && ticketVal) {
- if (!Number(ticketVal)) {
- return;
- }
- let movie = el('li', [
- el('span', nameVal),
- el('strong', `Hall: ${hallVal}`),
- el('div', [
- el('strong', `${ticketVal.toFixed(2)}`),
- input,
- archiveBtn
- ])
- ]);
- movieSection.appendChild(movie)
- archiveBtn.addEventListener('click', () => {
- if (!Number(input.value) || input.value == '') {
- return;
- }
- let delBtn = el('button', 'Delete')
- let archiveMovie = el('li', [
- el('span', nameVal),
- el('strong', `Total amount: ${(ticketVal * input.value).toFixed(2)}`),
- delBtn
- ])
- movie.remove();
- archiveSection.appendChild(archiveMovie);
- delBtn.addEventListener('click', () => {
- archiveMovie.remove();
- });
- clearBtn.addEventListener('click', () => {
- archiveMovie.parentElement.remove()
- })
- })
- }
- }
- function el(type, content, attributes) {
- const result = document.createElement(type);
- if (attributes !== undefined) {
- Object.assign(result, attributes);
- }
- if (Array.isArray(content)) {
- content.forEach(append);
- } else {
- append(content);
- }
- function append(node) {
- if (typeof node === 'string' || typeof node === 'number') {
- node = document.createTextNode(node);
- }
- result.appendChild(node);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement