Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movie seats js #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
288 changes: 288 additions & 0 deletions submissions/Nemooochka/movie-seats_js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="style.css">
<title>Movie seats</title>
</head>
<body>
<header>
<div class="container">
<h2>
Your favourite movie
</h2>
</div>
</header>
<main>
<div class="container">
<section class="cinema">
<div class="cinema-tickets_types">
<div class="cinema-tickets_type type-good">
<span class="type">Good -</span>
<span class="price">125</span>
<span class="currency">hrn</span>
</div>
<div class="cinema-tickets_type type-lux">
<span class="type">Super Lux -</span>
<span class="price">215</span>
<span class="currency">hrn</span>
</div>
</div>
<div class="cinema-screen">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 806 21" fill="#061420">
<path d="M3.2,20l-2,0.2l-0.3-4l2-0.2C136.2,5.3,269.6,0,403,0s266.8,5.3,400.2,16l2,0.2l-0.3,4l-2-0.2 C669.5,9.3,536.3,4,403,4S136.4,9.3,3.2,20z"></path>
</svg>
<span>Screen</span>
</div>
<div class="cinema-hall">
<form action="" autocomplete="off">
<div class="seats-row">
<div class="seat">
<input type="checkbox" id="seat_1_1" name="seat_1_1" aria-label="1 row 1 seat" value="1_1">
<label for="seat_1_1"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_2" name="seat_1_2" aria-label="1 row 2 seat" value="1_2">
<label for="seat_1_2"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_3" name="seat_1_3" aria-label="1 row 3 seat" value="1_3">
<label for="seat_1_3"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_4" name="seat_1_4" aria-label="1 row 4 seat" value="1_4">
<label for="seat_1_4"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_5" name="seat_1_5" aria-label="1 row 5 seat" value="1_5">
<label for="seat_1_5"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_6" name="seat_1_6" aria-label="1 row 6 seat" value="1_6">
<label for="seat_1_6"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_7" name="seat_1_7" aria-label="1 row 7 seat" value="1_7">
<label for="seat_1_7"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_8" name="seat_1_8" aria-label="1 row 8 seat" value="1_8">
<label for="seat_1_8"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_1_9" name="seat_1_9" aria-label="1 row 9 seat" value="1_9">
<label for="seat_1_9"></label>
</div>
</div>
<div class="seats-row">
<div class="seat">
<input type="checkbox" id="seat_2_1" name="seat_2_1" aria-label="2 row 1 seat" value="2_1">
<label for="seat_2_1"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_2" name="seat_2_2" aria-label="2 row 2 seat" value="2_2">
<label for="seat_2_2"></label>
</div>
<div class="seat seat-booked">
<input type="checkbox" id="seat_2_3" name="seat_2_3" aria-label="2 row 3 seat" value="2_3"
checked disabled>
<label for="seat_2_3"></label>
</div>
<div class="seat seat-booked">
<input type="checkbox" id="seat_2_4" name="seat_2_4" aria-label="2 row 4 seat" value="2_4"
checked disabled>
<label for="seat_2_4"></label>
</div>
<div class="seat seat-booked">
<input type="checkbox" id="seat_2_5" name="seat_2_5" aria-label="2 row 5 seat" value="2_5"
checked disabled>
<label for="seat_2_5"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_6" name="seat_2_6" aria-label="2 row 6 seat" value="2_6">
<label for="seat_2_6"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_7" name="seat_2_7" aria-label="2 row 7 seat" value="2_7">
<label for="seat_2_7"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_8" name="seat_2_8" aria-label="2 row 8 seat" value="2_8">
<label for="seat_2_8"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_9" name="seat_2_9" aria-label="2 row 9 seat" value="2_9">
<label for="seat_2_9"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_2_10" name="seat_2_10" aria-label="2 row 10 seat"
value="2_10">
<label for="seat_2_10"></label>
</div>
</div>
<div class="seats-row">
<div class="seat">
<input type="checkbox" id="seat_3_1" name="seat_3_1" aria-label="3 row 1 seat" value="3_1">
<label for="seat_3_1"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_2" name="seat_3_2" aria-label="3 row 2 seat" value="3_2">
<label for="seat_3_2"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_3" name="seat_3_3" aria-label="3 row 3 seat" value="3_3">
<label for="seat_3_3"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_4" name="seat_3_4" aria-label="3 row 4 seat" value="3_4">
<label for="seat_3_4"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_5" name="seat_3_5" aria-label="3 row 5 seat" value="3_5">
<label for="seat_3_5"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_6" name="seat_3_6" aria-label="3 row 6 seat" value="3_6">
<label for="seat_3_6"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_7" name="seat_3_7" aria-label="3 row 7 seat" value="3_7">
<label for="seat_3_7"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_8" name="seat_3_8" aria-label="3 row 8 seat" value="3_8">
<label for="seat_3_8"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_9" name="seat_3_9" aria-label="3 row 9 seat" value="3_9">
<label for="seat_3_9"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_3_10" name="seat_3_10" aria-label="3 row 10 seat"
value="3_10">
<label for="seat_3_10"></label>
</div>
</div>
<div class="seats-row">
<div class="seat">
<input type="checkbox" id="seat_4_1" name="seat_4_1" aria-label="4 row 1 seat" value="4_1">
<label for="seat_4_1"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_2" name="seat_4_2" aria-label="4 row 2 seat" value="4_2">
<label for="seat_4_2"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_3" name="seat_4_3" aria-label="4 row 3 seat" value="4_3">
<label for="seat_4_3"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_4" name="seat_4_4" aria-label="4 row 4 seat" value="4_4">
<label for="seat_4_4"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_5" name="seat_4_5" aria-label="4 row 5 seat" value="4_5">
<label for="seat_4_5"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_6" name="seat_4_6" aria-label="4 row 6 seat" value="4_6">
<label for="seat_4_6"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_7" name="seat_4_7" aria-label="4 row 7 seat" value="4_7">
<label for="seat_4_7"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_8" name="seat_4_8" aria-label="4 row 8 seat" value="4_8">
<label for="seat_4_8"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_9" name="seat_4_9" aria-label="4 row 9 seat" value="4_9">
<label for="seat_4_9"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_4_10" name="seat_4_10" aria-label="4 row 10 seat"
value="4_10">
<label for="seat_4_10"></label>
</div>
</div>
<div class="seats-row seats-row_lux">
<div class="seat seat-booked">
<input type="checkbox" id="seat_5_1" name="seat_5_1" aria-label="5 row 1 seat" value="5_1"
checked disabled>
<label for="seat_5_1"></label>
</div>
<div class="seat seat-booked">
<input type="checkbox" id="seat_5_2" name="seat_5_2" aria-label="5 row 2 seat" value="5_2"
checked disabled>
<label for="seat_5_2"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_3" name="seat_5_3" aria-label="5 row 3 seat" value="5_3">
<label for="seat_5_3"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_4" name="seat_5_4" aria-label="5 row 4 seat" value="5_4">
<label for="seat_5_4"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_5" name="seat_5_5" aria-label="5 row 5 seat" value="5_5">
<label for="seat_5_5"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_6" name="seat_5_6" aria-label="5 row 6 seat" value="5_6">
<label for="seat_5_6"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_7" name="seat_5_7" aria-label="5 row 7 seat" value="5_7">
<label for="seat_5_7"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_8" name="seat_5_8" aria-label="5 row 8 seat" value="5_8">
<label for="seat_5_8"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_9" name="seat_5_9" aria-label="5 row 9 seat" value="5_9">
<label for="seat_5_9"></label>
</div>
<div class="seat">
<input type="checkbox" id="seat_5_10" name="seat_5_10" aria-label="5 row 10 seat"
value="5_10">
<label for="seat_5_10"></label>
</div>
</div>
<div class="ticket-block"></div>
<div class="action">
<button type="submit" id="buyBtn" class="btn" disabled="disabled">
Buy
</button>
</div>
</form>
</div>
</section>
</div>
</main>
<div class="modal-order" id="modal-order">
<div class="modal-content">
<h4>
Your order:
</h4>
<div class="order-info">
<div class="order-info_row">
<span>Amount of tickets: </span><b class="total-tickets-amount"></b>
</div>
<div class="order-info_row">
<span>Total price: </span><b class="total-tickets-price"></b><b class="currency"> hrn</b>
</div>
</div>
<div class="btn-group">
<button id="cancel-order" class="btn btn-gray btn-small">Cancel</button>
<button id="proceed-order" class="btn btn-small">Proceed</button>
</div>
</div>
</div>

<script src="scripts.js"></script>
</body>
</html>
107 changes: 107 additions & 0 deletions submissions/Nemooochka/movie-seats_js/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

const cinemaHall = document.querySelector('.cinema-hall');
const ticketBlock = document.querySelector('.ticket-block');
const buyBtn = document.getElementById('buyBtn');
const cancelOrder = document.getElementById('cancel-order');
const priceRegular = document.querySelector('.cinema-tickets_type.type-good .price').textContent;
const priceLux = document.querySelector('.cinema-tickets_type.type-lux .price').textContent;
const modalOrder = document.getElementById('modal-order');
let totalTicketsAmount = 0;
let totalTicketsPrice = 0;


function renderChosenTicketBlockWrap() {
const wrapBlock = document.createElement('div');
wrapBlock.classList.add('wrap');

wrapBlock.innerHTML = (`
<h4>Tickets info:</h4>
<ul class="list-of-tickets"></ul>
`);

ticketBlock.appendChild(wrapBlock);
}

function generateChosenTicketBlock({seatRow, seatNumber, seatPrice}) {
return `<span class="seatRow">${seatRow} row</span>
<span class="seatNumber">${seatNumber} seat</span>
<b class="seatPrice">${seatPrice} hrn</b>`;
}

function renderChosenTicketBlock(ticketID, ticketInfo) {
const listOFTicketsBlock = document.querySelector('.list-of-tickets');

const priceBlock = document.createElement('li');
priceBlock.id = ticketID;

priceBlock.innerHTML = (generateChosenTicketBlock(ticketInfo));

listOFTicketsBlock.appendChild(priceBlock);
}

function addTicket(event, ticketID) {
let seatInfo = event.target.value.split('_');
let seatPrice = priceRegular;

if(event.target.closest('.seats-row').classList.contains('seats-row_lux')) {
seatPrice = priceLux;
}

const ticketInfo = {
seatRow: seatInfo[0],
seatNumber: seatInfo[1],
seatPrice: seatPrice
};

if(!ticketBlock.childNodes.length) renderChosenTicketBlockWrap();

renderChosenTicketBlock(ticketID, ticketInfo);
totalTicketsPrice += parseInt(seatPrice, 10);
totalTicketsAmount += 1;
}

function removeTicket(ticketID) {
let priceElement = document.getElementById(ticketID).querySelector('.seatPrice').innerHTML;
let ticketPrice = parseInt(priceElement, 10);
totalTicketsPrice -= ticketPrice;
totalTicketsAmount -= 1;

document.getElementById(ticketID).remove();
}



document.addEventListener("DOMContentLoaded", function () {

cinemaHall.addEventListener('change', (event) => {
let ticketID = event.target.value;
if(document.getElementById(ticketID)) {
removeTicket(ticketID);
} else {
addTicket(event, ticketID);
}

buyBtn.disabled = false;

if(!document.querySelector('.list-of-tickets').childNodes.length) {
ticketBlock.innerHTML = '';
buyBtn.disabled = true;
}
});

buyBtn.addEventListener('click', (event) => {
event.preventDefault();

modalOrder.style.display = 'block';
modalOrder.querySelector('.total-tickets-amount').innerHTML = totalTicketsAmount;
modalOrder.querySelector('.total-tickets-price').innerHTML = totalTicketsPrice;

});

cancelOrder.addEventListener('click', (event) => {
event.preventDefault();

modalOrder.style.display = 'none';
});
});
Loading