Advertisement
Liliana797979

viarno reshenie cinema tickets

Feb 13th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function cinemaTickets(input) {
  3.     let index = 0;
  4.     let counterKids = 0;
  5.     let counterStudents = 0;
  6.     let counterStandards = 0;
  7.  
  8.     let movie;
  9.  
  10.     while ((movie = input[index++]) !== 'Finish') {
  11.         let freeSpace = Number(input[index++]);
  12.         let usedSeats = 0;
  13.  
  14.         let typeOfTicket;
  15.  
  16.         while (usedSeats < freeSpace && (typeOfTicket = input[index++]) !== 'End') {
  17.             usedSeats++;
  18.             if (typeOfTicket === 'kid') {
  19.                 counterKids++;
  20.             } else if (typeOfTicket === 'student') {
  21.                 counterStudents++;
  22.             } else if (typeOfTicket === 'standard') {
  23.                 counterStandards++;
  24.             }
  25.         }
  26.         console.log(`${movie} - ${(usedSeats * 100 / freeSpace).toFixed(2)}% full.`);
  27.     }
  28.  
  29.     let totalTickets = counterKids + counterStudents + counterStandards;
  30.  
  31.     console.log(`Total tickets: ${totalTickets}`);
  32.     console.log(`${((counterStudents / totalTickets) * 100).toFixed(2)}% student tickets.`);
  33.     console.log(`${((counterStandards / totalTickets) * 100).toFixed(2)}% standard tickets.`);
  34.     console.log(`${((counterKids / totalTickets) * 100).toFixed(2)}% kids tickets.`);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement