Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemaTickets(input) {
- let index = 0;
- let standardTickets = 0;
- let studentTickets = 0;
- let kidsTickets = 0;
- let inputLine = input[index++];
- while(inputLine !== 'Finish') {
- let movieName = inputLine;
- let allTickets = Number(input[index++]);
- let availableTickets = allTickets;
- let ticketType = input[index++];
- while (ticketType !== 'End') {
- if (ticketType === 'standard') {
- standardTickets++;
- } else if (ticketType === 'kid') {
- kidsTickets++;
- } else {
- studentTickets++
- }
- availableTickets--;
- if (availableTickets === 0) {
- break;
- }
- ticketType = input[index++];
- }
- let boughtTickets = allTickets - availableTickets;
- let percentageFull = boughtTickets / allTickets * 100;
- console.log(`${movieName} - ${percentageFull.toFixed(2)}% full.`);
- inputLine = input[index++];
- }
- let totalTickets = kidsTickets + standardTickets + studentTickets;
- 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(`${(kidsTickets / totalTickets * 100).toFixed(2)}% kids tickets.`);
- }
Add Comment
Please, Sign In to add comment