Facebook
From Bitty Gibbon, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 142
  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.  
  9.     while (command !== "The restaurant is full") {
  10.         let numberOfPoepleInEachGroup = Number(command);
  11.  
  12.         if (numberOfPoepleInEachGroup < 5) {
  13.             moneyForGroup = 100 * numberOfPoepleInEachGroup;
  14.         } else if (numberOfPoepleInEachGroup >= 5) {
  15.             moneyForGroup = 70 * numberOfPoepleInEachGroup;
  16.         }
  17.        
  18.        
  19.         command = input.shift();
  20.         totalSumForGroup += moneyForGroup;
  21.  
  22.     }
  23.     if (totalSumForGroup > sumForSinger && command !== "The restaurant is full") {
  24.         console.log(`You have ${command} guests and ${(totalSumForGroup - sumForSinger)} leva left.`);
  25.     } else if (totalSumForGroup > sumForSinger && command == "The restaurant is full") {
  26.         console.log(`You have ${command} guests and ${(totalSumForGroup)} leva income, but no singer.`)
  27.     }
  28.  
  29.  
  30. }
  31.  
  32. solution(['3200', '5', '12', '6', '6', '12', 'The restaurant is full']
  33. );