vborislavova

05. Bachelor Party - sampleExam

Mar 28th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2. let moneyForSinger = Number(input.shift());
  3.             let command = input.shift();
  4.            
  5.             let counter = 0;
  6.            let total = 0;
  7.  
  8.             while (command != "The restaurant is full")
  9.             {
  10.                 let numberOfGuests = Number(command);
  11.                 counter += numberOfGuests;
  12.  
  13.  
  14.                 if (numberOfGuests < 5)
  15.                 {
  16.                     total += 100 * numberOfGuests;
  17.                 }
  18.                 else if (numberOfGuests >= 5)
  19.                 {
  20.                     total += 70 * numberOfGuests;
  21.                 }
  22.  
  23.                 command = input.shift();
  24.  
  25.  
  26.             }
  27.                 if (total >= moneyForSinger)
  28.                 {
  29.                     console.log(`You have ${counter} guests and ${total - moneyForSinger} leva left.`);
  30.                 }
  31.                 else
  32.                 {
  33.                     console.log(`You have ${counter} guests and ${total} leva income, but no singer.`);
  34.                 }
  35.             }
Advertisement
Add Comment
Please, Sign In to add comment