TZinovieva

Club JS

Nov 27th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function club(input) {
  2.     let wishedProfit = Number(input[0]);
  3.     let index = 1;
  4.     let command = input[index];
  5.     index++;
  6.     let drinksNumber = Number(input[index]);
  7.     index++;
  8.  
  9.     let singlePrice = 0;
  10.     let totalPrice = singlePrice * drinksNumber;
  11.     let order = 0;
  12.     while (command !== "Party!") {
  13.         singlePrice = Number(command.length);
  14.         totalPrice = singlePrice * drinksNumber;
  15.  
  16.         if (totalPrice % 2 !== 0) {
  17.             totalPrice -= totalPrice * 0.25;
  18.         }
  19.         order += totalPrice;
  20.        
  21.         if (order >= wishedProfit) {
  22.             console.log(`Target acquired.`);
  23.             break;
  24.         }
  25.         command = input[index];
  26.         index++;
  27.         drinksNumber = Number(input[index]);
  28.         index++;
  29.     }
  30.     if (command === "Party!") {
  31.         console.log(`We need ${(wishedProfit - order).toFixed(2)} leva more.`);    
  32.     }
  33.     console.log(`Club income - ${order.toFixed(2)} leva.`);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment