Advertisement
ProdanTenev

Account Balance

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