Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Tadjiev Codes
Tadjiev Codes
9,626 Points

Hi folks, Could someone please help me to understand why my Withdrawal doesn't work? https://w.trhou.se/o8sdi70poh

Hi folks, Could someone please help me to understand why my Withdrawal doesn't work? The Deposit works through a function and I thought that it would be the same in order to withdraw the amount and then display it? After the transaction, I need to update the screen with the new amount as well?

This is the snapshot link: https://w.trhou.se/o8sdi70poh

Steven Parker
Steven Parker
231,271 Points

:bookmark: I was alerted by your tag, but it ooks like Kris already has you covered. It's a good practice to wait a day before tagging anyone specifically, since help may come from other students or even staff.

Tadjiev Codes
Tadjiev Codes
9,626 Points

Alright Thank you Mr.Steven ) I really appreciate it) And I'll try to wait next time) You both of you are like my saviors🙌

3 Answers

Your withdrawing() function in pseudo code

if checking selected
    if not enough checking funds
        display insufficient funds     
else
    process checking withdrawal 

if savings selected
    if not enough savings funds
        display insufficient funds     
else
    process savings withdrawal         

when it should be

if checking selected
    if not enough checking funds
        display insufficient funds     
    else
        process checking withdrawal

if savings selected
    if not enough savings funds
        display insufficient funds     
    else
        process savings withdrawal  

So when checking is selected if checking selected is true and the checking funds are verified (and that is it). But then the if statement for savings is evaluated. if savings selected is false so the code for the savings else condition executes and savings funds are withdrawn.

To fix remove one closing bracket before else and place it after the nested if else statement for both checking and savings. This has been done in this updated snapshot. I also call the chequingAction() function after the log update for both deposits and withdrawals so the current balance is displayed.

Tadjiev Codes
Tadjiev Codes
9,626 Points

Thanks a lot Mr.Kris🙌 You really helped me out to figure out all the problems🙌 You both of you are like my saviors with Steven in this community🙌

1) You have typo in onclick here:

<input type="button" value="Withdraw" oncllick="withdrawing()" />

so withdrawing() doesn't execute when the button is clicked

2) In withdrawing() check the brackets for your inner if statements. For example the code to process a withdrawal from checking

 chequing = parseFloat(chequing) - parseFloat(withdrawingAmount);
                var withdrawalAmountToChequing = "Withdrawal: $ " + withdrawingAmount + " Chequing Account";

should execute if (withdrawingAmount > chequing) is false. However based on the brackets it executes if (document.getElementById("ddAccountTypeMenu").selectedIndex === 0) is false. Similar thing happens with withdrawal from savings. That is why amounts are withdrawn from the opposite account selected.

Tadjiev Codes
Tadjiev Codes
9,626 Points

Hi Thanks a lot for the response))) That typo is so crazy that how I didn't even notice it. but I still can't make the withdrawal work. Do you mean the brackets of nested if statements {} are making it wrong? I tried to remove second brackets and move other ways but it still didn't work.