Advertisement
Liliana797979

account balance

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