vborislavova

05.Account Balance - while - loops

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