Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tripExpenses(input) {
- let days = Number(input[0]);
- let command;
- let dayCash = 0.0;
- let inputIndex = 1;
- for (let i = 0; i < days; i++) {
- let dayProducts = 0;
- dayCash += 60;
- while (true) {
- command = input[inputIndex++];
- if (command == "Day over") {
- console.log(`Money left from today: ${dayCash.toFixed(2)}. You\'ve bought ${dayProducts} products.`);
- break;
- }
- let productPrice = Number(command);
- if (productPrice <= dayCash) {
- dayCash -= productPrice;
- dayProducts++;
- }
- if (dayCash == 0) {
- console.log(`Daily limit exceeded! You\'ve bought ${dayProducts} products.`);
- break;
- }
- }
- }
- return;
- }
Advertisement
Advertisement