Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let budget = +input.shift();
- let product = input.shift();
- let price = 0;
- let productsCounter = 0;
- let moneySpent = 0;
- let boughtProducts = 0;
- while (product !== 'Finish') {
- productsCounter++;
- if (product == 'Star') {
- price = 5.69;
- } else if (product == 'Angel') {
- price = 8.49;
- } else if (product == 'Lights') {
- price = 11.20;
- } else if (product == 'Wreath') {
- price = 15.50;
- } else if (product == 'Candle') {
- price = 3.59;
- }
- if (productsCounter % 3 == 0) {
- price = 0.7;
- }
- budget -= price;
- moneySpent += price;
- if (budget price) {
- let diff = price - budget;
- console.log(`Not enough money! You need ${diff} lv more.`);
- break;
- }
- boughtProducts++;
- product = input.shift();
- if (product == 'Finish') {
- console.log(`Congratulations! You bought everything!`);
- break;
- }
- }
- console.log(`${boughtProducts} items - ${moneySpent.toFixed(2)} lv spent.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement