Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function touristshop(input) {
- let budget = Number(input.shift());
- //let budgetTmp = budget
- let price = 0;
- let command = input.shift();
- let counter = 0;
- while (command != "Stop") {
- counter++;
- if (counter % 3 == 0) {
- price += Number(input.shift())/2
- } else {
- price += Number(input.shift())
- }
- if (price > budget) {
- console.log(You don't have enough money!);
- console.log(You need ${Math.abs(price - budget).toFixed(2)} leva!);
- return
- } //else {
- /* budgetTmp -= price;
- //result += price;
- if (budgetTmp == 0) {
- break;
- } */
- //}
- command = input.shift()
- }
- console.log(You bought ${counter} products for ${price.toFixed(2)} leva.);
- }
Advertisement
Add Comment
Please, Sign In to add comment