TZinovieva

Cinema Tickets JS

Nov 2nd, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemaTickets(input) {
  2.     let index = 0;
  3.     let command = input[index];
  4.     index++;
  5.  
  6.     let studentTickets = 0;
  7.     let standardTickets = 0;
  8.     let kidTickets = 0;
  9.  
  10.    
  11.     while (command !== "Finish") {
  12.         let vacantSeats = Number(input[index]);
  13.         index++;
  14.  
  15.         let ticketType = input[index];
  16.         index++;
  17.        
  18.         let soldSeats = 0;
  19.         while (ticketType !== "End") {
  20.             soldSeats++;
  21.  
  22.             if (ticketType === "student") {
  23.                 studentTickets++
  24.             } else if ( ticketType === "standard") {
  25.                 standardTickets++;
  26.             } else {
  27.                 kidTickets++;
  28.             }
  29.             if (soldSeats === vacantSeats) {
  30.                 break;
  31.             }
  32.             ticketType = input[index];
  33.             index++;
  34.         }
  35.         let soldSeatsPercentage = soldSeats / vacantSeats * 100;
  36.         console.log(`${command} - ${soldSeatsPercentage.toFixed(2)}% full.`);
  37.    
  38.         command = input[index];
  39.         index++;
  40.     }
  41.     let totalTickets = standardTickets + studentTickets + kidTickets;
  42.     console.log(`Total tickets: ${totalTickets}`);
  43.     console.log(`${(studentTickets / totalTickets * 100).toFixed(2)}% student tickets.`);
  44.     console.log(`${(standardTickets / totalTickets * 100).toFixed(2)}% standard tickets.`);
  45.     console.log(`${(kidTickets / totalTickets * 100).toFixed(2)}% kids tickets.`);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment