Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vacation(input) {
- let moneyNeeded = Number(input[0]);
- let budget = Number(input[1]);
- let spendDay = 0, saveDays = 0, index = 2;
- while (moneyNeeded > budget && spendDay !== 5) {
- let command = input[index++];
- let money = Number(input[index++]);
- if (command === "spend") {
- budget -= money;
- if (budget < 0) {
- budget = 0;
- }
- spendDay++;
- } else {
- budget += money;
- spendDay = 0;
- }
- saveDays++;
- }
- if (budget < moneyNeeded) {
- console.log(`You can't save the money.\n${saveDays}`)
- } else {
- console.log(`You saved the money for ${saveDays} days.`);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement