Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemaTickets(input) {
  2.  
  3.     let film = input.shift();
  4.     let totalTickets = 0;
  5.     let totalstudents = 0;
  6.     let totalKids = 0;
  7.     let totalStandard = 0;
  8.  
  9.     while (film !== "Finish") {
  10.  
  11.         let freeSpace = Number(input.shift());
  12.         let ticket = input.shift();
  13.         let soldTickets = 0;
  14.  
  15.         while (ticket !== "End"){
  16.             if(ticket === "standard"){
  17.                 totalStandard++;
  18.             }else if (ticket === "student") {
  19.                 totalstudents++;
  20.             }else if (ticket === "kid"){
  21.                 totalKids++;
  22.             }
  23.             totalTickets++;
  24.             soldTickets++;
  25.  
  26.             if(soldTickets >= freeSpace){
  27.                 break;
  28.             }
  29.             ticket = input.shift();
  30.         }
  31.         let capacityProcentage = (soldTickets / freeSpace) * 100;
  32.         console.log(`${film} - ${capacityProcentage.toFixed(2)}% full.`);
  33.        
  34.         film = input.shift();
  35.  
  36.     }
  37.     console.log(`Total tickets: ${totalTickets}`);
  38.     console.log(`${((totalstudents / totalTickets) * 100).toFixed(2)}% student tickets.`);
  39.     console.log(`${((totalStandard / totalTickets) * 100).toFixed(2)}% standard tickets.`);
  40.     console.log(`${((totalKids / totalTickets ) * 100).toFixed(2)}% kid tickets.`)
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement