georgiev955

Cinema Tickets

Mar 14th, 2023
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.   let totalTickets = 0;
  3.   let studentTickets = 0;
  4.   let standardTickets = 0;
  5.   let childTickets = 0;
  6.   let index = 0;
  7.   let command;
  8.  
  9.   while((command = input[index]) !== "Finish") {
  10.     let currentMovie = command;
  11.     index++;
  12.     let totalSeats = Number(input[index]);
  13.     index++;
  14.     let command2;
  15.     let usedSeats = 0;
  16.     while(((command2 = input[index]) !== "End") && totalSeats > usedSeats) {
  17.       let ticketType = command2;
  18.       index++;
  19.       usedSeats++;
  20.       if (ticketType === "student") {
  21.         studentTickets++;
  22.       } else if (ticketType === "standard") {
  23.         standardTickets++;
  24.       } else if (ticketType === "kid") {
  25.         childTickets++;
  26.       }
  27.     }
  28.     console.log(`${currentMovie} - ${((usedSeats)/totalSeats*100).toFixed(2)}% full.`);
  29.     if (command2 === "End") {
  30.       index++;
  31.     }
  32.   }
  33.   totalTickets = studentTickets+standardTickets+childTickets;
  34.   console.log(`Total tickets: ${totalTickets}`);
  35.   console.log(`${(studentTickets/totalTickets*100).toFixed(2)}% student tickets.`);
  36.   console.log(`${(standardTickets/totalTickets*100).toFixed(2)}% standard tickets.`);
  37.   console.log(`${(childTickets/totalTickets*100).toFixed(2)}% kids tickets.`);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment