Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2021
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function touristShop(input) {
  2.     let index = 0;
  3.     let budget = Number(input[index]);
  4.     index++;
  5.     let command = input[index];
  6.     index++;
  7.     let counter = 0;
  8.     let priceCounter = 0;
  9.  
  10.  
  11.     while(command !== "Stop"){
  12.         let price = Number(input[index]);
  13.         index++;
  14.         counter++
  15.  
  16.         if(counter % 3 === 0){
  17.             price = price / 2
  18.         }
  19.  
  20.         priceCounter += price;
  21.         budget -= price
  22.  
  23.         command = input[index];
  24.         index++;
  25.  
  26.         if(budget < 0){
  27.             console.log("You don't have enough money!");
  28.             console.log(`You need ${Math.abs(budget).toFixed(2)} leva!`)
  29.             return;
  30.         }
  31.     }
  32.  
  33.     console.log(`You bought ${counter} products for ${(priceCounter).toFixed(2)} leva.`)
  34.  
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement