kalitarix

Bachelor party

Apr 3rd, 2019
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.     let singerPrice = input[0];
  3.     let totalSum = 0;
  4.     let guestCount = 0;
  5.  
  6.     for (let index = 1; index < input.length; index++) {
  7.         if (input[index] === 'The restaurant is full') {
  8.             break;
  9.         }
  10.  
  11.         let groupCount = input[index];
  12.         guestCount += Number(groupCount);
  13.  
  14.         if (groupCount < 5) {
  15.             totalSum += groupCount * 100;
  16.         } else {
  17.             totalSum += groupCount * 70;
  18.         }
  19.     }
  20.  
  21.     if (totalSum >= singerPrice) {
  22.         console.log(`You have ${guestCount} guests and ${totalSum - singerPrice} leva left.`);
  23.     } else {
  24.         console.log(`You have ${guestCount} guests and ${totalSum} leva income, but no singer.`);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment