Advertisement
Guest User

Untitled

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