Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function holliday (input) {
- let exucrsionPrice = Number (input [0])
- let startMoney = Number (input [1])
- let days = 0
- let daysSpent = 0
- let action = input [2]
- let moneyAction = input [3]
- index = 4
- while (exucrsionPrice > startMoney){
- days++
- if (action === 'spend'){
- daysSpent++
- if (moneyAction > startMoney){
- startMoney=0
- }else{
- startMoney = startMoney - moneyAction
- }
- if (daysSpent >= 5){
- console.log("You can't save the money.");
- console.log(days);
- return
- }
- }else{
- startMoney = startMoney + moneyAction
- daysSpent = 0
- }
- action = input [index]
- index++
- moneyAction = Number (input [index])
- index++
- }
- console.log(`You saved the money for ${days} days.`);
- }
- holliday (["2000",
- "1000",
- "spend",
- "1200",
- "save",
- "2000"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement