Advertisement
Spocoman

Cinema

Jan 4th, 2022 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinema(input) {
  2.     let seats = Number(input[0]);
  3.     let totalSum = 0;
  4.     let index = 1;
  5.     let command;
  6.  
  7.     while ((command = input[index++]) != "Movie time!") {
  8.         let people = Number(command);
  9.         if (people > seats) {
  10.             break;
  11.         } else if (people % 3 === 0) {
  12.             totalSum -= 5;
  13.         }
  14.         totalSum += people * 5;
  15.         seats -= people;    
  16.     }
  17.  
  18.     if (command === "Movie time!") {
  19.         console.log(`There are ${seats} seats left in the cinema.`);
  20.     } else {
  21.         console.log("The cinema is full.");
  22.     }
  23.     console.log(`Cinema income - ${totalSum} lv.`);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement