Liliana797979

viarno reshenie club with while loop

Feb 24th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function club(input) {
  2.     let index = 0;
  3.     let profit = Number(input[index]);
  4.     index++;
  5.     let income = 0;
  6.     let command = input[index];
  7.     index++;
  8.     let isPartyCommand = true;
  9.     while (command !== "Party!") {
  10.         let name = command;
  11.         let count = Number(input[index]);
  12.         index++;
  13.         let drinksPrice = name.length * count;
  14.         if (drinksPrice % 2 !== 0) {
  15.             drinksPrice = drinksPrice * 0.75;
  16.         }
  17.         income += drinksPrice;
  18.  
  19.         if (income >= profit) {
  20.             isPartyCommand = false;
  21.             break;
  22.         }
  23.         command = input[index];
  24.         index++;
  25.     }
  26.     if (isPartyCommand) {
  27.         let diff = profit - income;
  28.         console.log(`We need ${diff.toFixed(2)} leva more.`);
  29.     } else {
  30.         console.log(`Target acquired.`);
  31.     }
  32.     console.log(`Club income - ${income.toFixed(2)} leva.`);
  33. }
  34.  
  35. club(["500",
  36. "Bellini",
  37. "6",
  38. "Bamboo",
  39. "7",
  40. "Party!"]);
Advertisement
Add Comment
Please, Sign In to add comment