TZinovieva

Account Balance

Jun 9th, 2022
43
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.     let sum = 0;
  6.     while (command !== "NoMoreMoney") {
  7.         let deposit = Number(command);
  8.  
  9.         if (deposit < 0) {
  10.             console.log(`Invalid operation!`);
  11.             break;
  12.         }
  13.         sum += deposit;
  14.         console.log(`Increase: ${(deposit).toFixed(2)}`);
  15.         command = input[index];
  16.         index++;
  17. }
  18.     console.log(`Total: ${(sum).toFixed(2)}`);
  19. }  
Advertisement
Add Comment
Please, Sign In to add comment