Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaTickets(input) {
- let index = 0;
- let counterKids = 0;
- let counterStudents = 0;
- let counterStandards = 0;
- let movie;
- while ((movie = input[index++]) !== 'Finish') {
- let freeSpace = Number(input[index++]);
- let usedSeats = 0;
- let typeOfTicket;
- while (usedSeats < freeSpace && (typeOfTicket = input[index++]) !== 'End') {
- usedSeats++;
- if (typeOfTicket === 'kid') {
- counterKids++;
- } else if (typeOfTicket === 'student') {
- counterStudents++;
- } else if (typeOfTicket === 'standard') {
- counterStandards++;
- }
- }
- console.log(`${movie} - ${(usedSeats * 100 / freeSpace).toFixed(2)}% full.`);
- }
- let totalTickets = counterKids + counterStudents + counterStandards;
- console.log(`Total tickets: ${totalTickets}`);
- console.log(`${((counterStudents / totalTickets) * 100).toFixed(2)}% student tickets.`);
- console.log(`${((counterStandards / totalTickets) * 100).toFixed(2)}% standard tickets.`);
- console.log(`${((counterKids / totalTickets) * 100).toFixed(2)}% kids tickets.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement