Advertisement
Spocoman

Account Balance

Jan 4th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function accountBalance(input) {
  2.     let index = 0;
  3.     let total = 0;
  4.     while (input[index] !== "NoMoreMoney"){
  5.         let cash = parseFloat(input[index]);
  6.         if (cash < 0){
  7.             console.log(`Invalid operation!`);
  8.             break;
  9.         } else{
  10.             console.log(`Increase: ${cash.toFixed(2)}`);
  11.             total += cash;
  12.         }
  13.         index++;
  14.     }
  15.     console.log(`Total: ${total.toFixed(2)}`)
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement