Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function touristShop(input) {
- let budget = Number(input[0]);
- let index = 1;
- let command = input[index++];
- let productsCount = 0;
- let totalPrice = 0;
- let notEnought = false;
- let daysCount = 1;
- while (command !== "Stop") {
- let productName = command;
- let priceProduct = Number(input[index++]);
- if (daysCount % 3 === 0) {
- priceProduct /= 2;
- }
- if (priceProduct > budget) {
- notEnought = true;
- console.log(`You don't have enough money!`);
- console.log(`You need ${priceProduct - budget} leva!`);
- break;
- }
- budget -= priceProduct;
- totalPrice += priceProduct;
- productsCount++;
- daysCount++;
- command = input[index++]
- }
- if (!notEnought) {
- console.log(`You bought ${productsCount} products for ${totalPrice} leva.`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement