Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shop(inputData) {
- let budget = Number(inputData.shift());
- let nameOfProduct = inputData.shift();
- let curProduct = 0;
- let allPrice = 0;
- while (nameOfProduct !== 'Stop') {
- let priceOfProduct = Number(inputData.shift());
- if ((curProduct + 1) % 3 === 0) {
- priceOfProduct = priceOfProduct / 2;
- }
- budget -= priceOfProduct;
- if (budget < 0) {
- break;
- }
- curProduct++;
- allPrice += priceOfProduct;
- nameOfProduct = inputData.shift();
- }
- if (budget >= 0) {
- console.log(`You bought ${curProduct} products for ${(allPrice).toFixed(2)} leva.`);
- } else if (budget < 0) {
- console.log(`You don't have enough money!`);
- console.log(`You need ${Math.abs(budget).toFixed(2)} leva!`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement