Advertisement
gskorchev

account balance

Feb 4th, 2019
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function accountBalance(input) {
  2.     let n = Number(input.shift());
  3.     let counter = 0;
  4.     let balance = 0.0;
  5.  
  6.     while (counter < n) {
  7.         let amount = Number(input.shift());
  8.         if (amount < 0) {
  9.             console.log("Invalid operation!");
  10.             break;
  11.         }
  12.         balance += amount;
  13.         console.log(`Increase: ${amount.toFixed(2)}`);
  14.         counter++;
  15.     }
  16.     console.log(`Total: ${balance.toFixed(2)}`);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement