Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaTickets(input) {
- let index = 0;
- let command = input[index];
- index++;
- let studentTickets = 0;
- let standardTickets = 0;
- let kidTickets = 0;
- while (command !== "Finish") {
- let vacantSeats = Number(input[index]);
- index++;
- let ticketType = input[index];
- index++;
- let soldSeats = 0;
- while (ticketType !== "End") {
- soldSeats++;
- if (ticketType === "student") {
- studentTickets++
- } else if ( ticketType === "standard") {
- standardTickets++;
- } else {
- kidTickets++;
- }
- if (soldSeats === vacantSeats) {
- break;
- }
- ticketType = input[index];
- index++;
- }
- let soldSeatsPercentage = soldSeats / vacantSeats * 100;
- console.log(`${command} - ${soldSeatsPercentage.toFixed(2)}% full.`);
- command = input[index];
- index++;
- }
- let totalTickets = standardTickets + studentTickets + kidTickets;
- console.log(`Total tickets: ${totalTickets}`);
- console.log(`${(studentTickets / totalTickets * 100).toFixed(2)}% student tickets.`);
- console.log(`${(standardTickets / totalTickets * 100).toFixed(2)}% standard tickets.`);
- console.log(`${(kidTickets / totalTickets * 100).toFixed(2)}% kids tickets.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment