Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let movieTitle = input.shift();
- let student = 0;
- let standard = 0;
- let kid = 0;
- while (movieTitle != "Finish") {
- let ticketCounter = 0;
- let seats = Number(input.shift());
- let ticketType = "";
- while (ticketType != "End" && seats > ticketCounter) {
- ticketType = input.shift();
- if (ticketType == "student") {
- student++;
- ticketCounter++;
- } else if (ticketType == "standard") {
- standard++;
- ticketCounter++;
- } else if (ticketType == "kid") {
- kid++;
- ticketCounter++;
- }
- }
- let percentage = ((ticketCounter * 1.0) / seats) * 100;
- console.log(`${movieTitle} - ${percentage.toFixed(2)}% full.`);
- movieTitle = input.shift();
- }
- let totalTickets = student + standard + kid;
- console.log(`Total tickets: ${totalTickets}`);
- console.log(
- `${(((student * 1.0) / totalTickets) * 100).toFixed(2)}% student tickets.`
- );
- console.log(
- `${(((standard * 1.0) / totalTickets) * 100).toFixed(2)}% standard tickets.`
- );
- console.log(
- `${(((kid * 1.0) / totalTickets) * 100).toFixed(2)}% kids tickets.`
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement