Advertisement
GalinaKG

Untitled

Mar 18th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. function cinemaTickets2 (input) {
  2. let index = 0;
  3. let command = input[index];
  4. let studentTicket = 0;
  5. let standardTicket = 0;
  6. let kidTicket = 0;
  7.  
  8. while (command !== "Finish") {
  9. let nameOfMovie = input[index];
  10. index++
  11. let freeSpaces = Number(input[index]);
  12. index++;
  13. let type = input[index];
  14. let ticketsforMovie = 0;
  15.  
  16. while (type !== "End") {
  17.  
  18. switch (type) {
  19. case "student": studentTicket++; break;
  20. case "standard": standardTicket++; break;
  21. case "kid": kidTicket++; break;
  22. }
  23. ticketsforMovie++;
  24.  
  25. if (ticketsforMovie >= freeSpaces) {
  26. break;
  27. }
  28.  
  29. index++;
  30. type = input[index];
  31. }
  32. let percTicketsForMovie = ticketsforMovie /freeSpaces * 100;
  33. console.log(`${nameOfMovie} - ${percTicketsForMovie.toFixed(2)}% full.`);
  34.  
  35. index++
  36. command = input[index];
  37. }
  38. let totalTicket = studentTicket + standardTicket + kidTicket;
  39. let pStudent = studentTicket / totalTicket * 100;
  40. let pStandard = standardTicket / totalTicket * 100;
  41. let pKid = kidTicket / totalTicket * 100;
  42.  
  43. console.log(`Total tickets: ${totalTicket}`);
  44. console.log(`${pStudent.toFixed(2)}% student tickets.`);
  45. console.log(`${pStandard.toFixed(2)}% standard tickets.`);
  46. console.log(`${pKid.toFixed(2)}% kids tickets.`);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement