Advertisement
Liliana797979

vqrno reshenie na cinema while loop

Dec 27th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinema(input) {
  2.     let capacityOfHall = input[0];
  3.     let index = 1;
  4.     let people = input[index];
  5.    
  6.     let totalPeople = 0;
  7.     let totalMoney = 0;
  8.     let isFull = false;
  9.    
  10.     while (people !== "Movie time!") {
  11.         totalPeople += people;
  12.        
  13.         if (capacityOfHall < totalPeople) {
  14.             isFull = true;
  15.             break;
  16.         }
  17.        
  18.         totalMoney += people * 5;
  19.             if (people % 3 === 0) {
  20.                 totalMoney -= 5;
  21.             }
  22.  
  23.         index++;
  24.         people = input[index];
  25.     }
  26.    
  27.      if (!isFull) {
  28.             let diff = capacityOfHall - totalPeople;
  29.             console.log(`There are ${diff} seats left in the cinema.`);
  30.      } else {
  31.             console.log(`The cinema is full.`);
  32.      }
  33.        
  34.      console.log(`Cinema income - ${totalMoney} lv.`);
  35. }
  36.  
  37. cinema([60, 10, 6, 3, 20, 15, "Movie time!"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement