Advertisement
Liliana797979

viarno reshenie club with for loop

Feb 20th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function club(input) {
  2.     let target = Number(input[0]);
  3.     let coctail = input;
  4.     let pricePerCoctail = 0;
  5.     let totalPrice = 0;
  6.     let pricePerOrder = 0;
  7.  
  8.     for(let i = 1; i < coctail.length; i++) {
  9.         if(i % 2 === 1) {
  10.             let eachCoctail = coctail[i];
  11.             let coctailCount = Number(coctail[i+1]);
  12.             if(eachCoctail !== "Party!") {
  13.                 pricePerCoctail = Number(eachCoctail.length);
  14.                 pricePerOrder = pricePerCoctail * coctailCount;
  15.                 if(pricePerOrder % 2 === 1) {
  16.                     pricePerOrder *= 0.75;
  17.                 }
  18.                 totalPrice += pricePerOrder;
  19.  
  20.             if(target <= totalPrice) {
  21.                 console.log(`Target acquired.`);
  22.                 console.log(`Club income - ${totalPrice.toFixed(2)} leva.`);
  23.             }  
  24.             }
  25.             else if(eachCoctail === "Party!") {
  26.                 console.log(`We need ${(target - totalPrice).toFixed(2)} leva more.`);
  27.                 console.log(`Club income - ${totalPrice.toFixed(2)} leva.`);
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement