TZinovieva

Account Balance

Oct 11th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function accountBalance(input) {
  2.     let index = 0;
  3.     let command = input[index];
  4.     index++;
  5.    
  6.     let sum = 0;
  7.     while (command !== "NoMoreMoney") {
  8.         let deposit = Number(command);
  9.         if (deposit < 0) {
  10.             console.log(`Invalid operation!`);
  11.             break;
  12.         }
  13.         sum += deposit;
  14.         console.log(`Increase: ${deposit.toFixed(2)}`);
  15.        
  16.         command = input[index];
  17.         index++;
  18.     }
  19.     console.log(`Total: ${sum.toFixed(2)}`);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment