Ivankooo1

BachelorParty

Jul 1st, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function BachelorParty(input){
  2. let singer = Number(input.shift());
  3. let sumPeople = 0;
  4. let sum = 0;
  5.  
  6. let command = input.shift();
  7. while(command !== 'The restaurant is full'){
  8. let people = Number(command);
  9. sumPeople += people;
  10.  
  11. if(people < 5){
  12. sum += people * 100;
  13.  
  14. }else if(people >= 5){
  15. sum += people * 70;
  16. }
  17.  
  18. command = input.shift();
  19. }
  20.  
  21. if(sum >= singer){
  22. let leftMoney = sum - singer;
  23. console.log(`You have ${sumPeople} guests and ${leftMoney} leva left.`);
  24. }else{
  25. console.log(`You have ${sumPeople} guests and ${sum} leva income, but no singer.`);
  26. }
  27.  
  28. }
  29. BachelorParty([3200,
  30. 5,
  31. 12,
  32. 6,
  33. 6,
  34. 12,
  35. 'The restaurant is full'
  36.  
  37. ]);
Advertisement
Add Comment
Please, Sign In to add comment