Advertisement
PowerCell46

Cinema JS

Oct 18th, 2022
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinema(input) {
  2.     let index = 0;
  3.     let capacityOfTheHall = Number(input[index]);
  4.     index++;
  5.     let currentNumberOfPeople = input[index];
  6.     let priceOfATicket = 5;
  7.    
  8.     let income = 0;
  9.     let numberOfPeople = 0;
  10.    
  11.     while(currentNumberOfPeople !== "Movie time!" && numberOfPeople < capacityOfTheHall) {
  12.         currentNumberOfPeople = Number(input[index]);
  13.         numberOfPeople += currentNumberOfPeople;
  14.         if(numberOfPeople > capacityOfTheHall) {continue;}
  15.         if(currentNumberOfPeople % 3 === 0) {
  16.         income -= 5;
  17.         }
  18.         income += currentNumberOfPeople * priceOfATicket;
  19.         index++;
  20.         currentNumberOfPeople = input[index];
  21.     }
  22.    
  23.     if(currentNumberOfPeople === "Movie time!") {
  24.         let leftSeats = capacityOfTheHall - numberOfPeople;
  25.         console.log( "There are " + leftSeats + " seats left in the cinema.")
  26.     } else if(numberOfPeople >= capacityOfTheHall) {
  27.         console.log("The cinema is full.");
  28.     }
  29.      console.log("Cinema income - " + income + " lv.");
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement