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