svephoto

Cinema Tickets [JavaScript]

Jul 24th, 2021
1,003
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemaTickets(input) {
  2.     let studentTickets = 0;
  3.     let standardTickets = 0;
  4.     let kidsTickets = 0;
  5.  
  6.     let movie = input.shift();
  7.  
  8.     while (movie != "Finish") {
  9.         let movieTickets = 0;
  10.         let capacity = Number(input.shift());
  11.         let ticket = "";
  12.  
  13.         while (ticket != "End" && capacity > movieTickets) {            
  14.             ticket = input.shift();
  15.  
  16.             if (ticket == "student") {
  17.                 studentTickets++;
  18.                 movieTickets++;
  19.             } else if (ticket == "standard") {
  20.                 standardTickets++;
  21.                 movieTickets++;
  22.             } else if (ticket == "kid") {
  23.                 kidsTickets++;
  24.                 movieTickets++;
  25.             }        
  26.         }
  27.        
  28.         console.log(`${movie} - ${(movieTickets / capacity * 100).toFixed(2)}% full.`);
  29.  
  30.         movie = input.shift();      
  31.     }
  32.  
  33.     let totalTickets = standardTickets + kidsTickets + studentTickets;
  34.    
  35.     console.log(`Total tickets: ${totalTickets}`);
  36.     console.log(`${(studentTickets / totalTickets * 100).toFixed(2)}% student tickets.`);
  37.     console.log(`${(standardTickets / totalTickets * 100).toFixed(2)}% standard tickets.`);
  38.     console.log(`${(kidsTickets / totalTickets * 100).toFixed(2)}% kids tickets.`)
  39. }
  40.  
RAW Paste Data