javascripthtmlcssfunctionbank

Javascript coding problem when I want to add balance from withdraw input


I am trying to change the amount of withdraw balance when I click withdraw button. But when I click withdraw button, only the withdraw amount changes. Where is the problem? The deposit button works fine. Please check my code. code link : https://basir5101.github.io/ta-ta-bank/ repository link: https://github.com/basir5101/ta-ta-bank/blob/master/index.html/


Solution

  • On withdrawal you are updating the withdraw wallet amount which is perfect, But you are not updating the currentBalance wallet. Have added the extra line for updating current balance when you update withdraw, now it's working fine:

    withdrawButton.addEventListener('click', function(){
        const withdrawInput = document.getElementById('withdrawInput').value;
        const withdrawInputNumber = parseFloat(withdrawInput);
        console.log(withdrawInputNumber);
        balance('currentWithdraw', withdrawInputNumber);
        balance('currentBalance', withdrawInputNumber);
    
        document.getElementById('withdrawInput').value = "";
    })