Advertisement
Didart

Account Balance

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