Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function food(input) {
- let budget = Number(input.shift());
- let product = input.shift();
- let price = Number(input.shift());
- let total = 2.5;
- let count = 0;
- while (product != 'Order') {
- total += price;
- if (total <= budget) {
- count++;
- } else {
- total -= price;
- console.log(`You will exceed the budget if you order this!`);
- }
- product = input.shift();
- price = Number(input.shift());
- }
- console.log(`You ordered ${count} items!`);
- console.log(`Total: ${total.toFixed(2)}`);
- }
- food(['25.00', 'Soup', '3.50', 'Salad', '7.80', 'Fish', '9.00', 'Cake', '5.00', 'Ice cream', '2.00', 'Order']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement