Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Excursion(input){
- let days = Number(input.shift());
- let saveMoney = 0;
- for(let i = 1;i<= days;i++){
- let limit = 60;
- let countProduct = 0;
- let command = input.shift();
- while(command !== 'Day over'){
- let priceProduct = Number(command);
- if(priceProduct > 60){
- command = input.shift();
- continue;
- }
- limit += saveMoney;
- limit -= priceProduct;
- countProduct++;
- if(limit <= 0){
- console.log(`Daily limit exceeded! You've bought ${countProduct} products.`);
- break;
- }
- command = input.shift();
- }
- if(limit > 0){
- saveMoney = limit;
- console.log(`Money left from today: ${saveMoney.toFixed(2)}.`);
- console.log(`You've bought ${countProduct} products.`);
- }
- }
- }
- Excursion([
- 3,
- 20,
- 40,
- 40,
- 15,
- 'Day over',
- 15,
- 5,
- 10,
- 17,
- 10,
- 'Day over'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment