Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tripExpenses(input) {
- let vacationDays = Number(input.shift());
- for(let i = 0; i < vacationDays; i++) {
- let limit = 60;
- let productCount = 0;
- let command = input.shift();
- let totalPriceForDay = 0;
- let moneyLeft = 0;
- while(command !== 'Day over') {
- let priceOfProduct = Number(command);
- totalPriceForDay += priceOfProduct;
- productCount++;
- if(totalPriceForDay >= 60) {
- console.log(`Daily limit exceeded! You've bought ${productCount} products.`)
- break;
- }
- command = input.shift();
- }
- if(totalPriceForDay < 60) {
- moneyLeft = limit - totalPriceForDay;
- console.log(`Money left from today: ${moneyLeft.toFixed(2)}. You've bought ${productCount} products.`)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement