I’m trying to create my first web app, a tax calculator problem is the first time I press the button it gives me a wrong figure…but when I do Ctrl+s to save the code again ,and press the button a second time it gives the correct results.How can I correct that so the first button press gives the correct answer? You can also advise on best practices to write code I’m still learning so I just kind of write it how it comes to my head …form/script.js at master · twicemuch/form · GitHub that’s the link to my js code on GitHub
Can you walk us through an example of what you enter into the form and what you expect to see happen vs. what happens?
Which form fields does the user actually need to fill out before clicking the PAYE button?
The ones under titles basic salary and allowances.
I am not getting the same values in the form fields on the right side that you show above when I enter the same values you show above, so you have not made it clear what you are expecting to see when the button is clicked using
Basic Salary = 5000 and
Allowances = 2000.
When I enter these values I see the following regardless of how many times I click the PAYE button.
Yes I’m getting those same results on the first click ,but when I save the code and click again it gives me the results in the first image .
Wish there was a way I could share a short video of what I’m explaining so you could see
Seems to be because of how you are calling
findGross and using
grossTotal in the outer scope. If you remove the outer scope code and replace all instances of
grossTotal with a call to
findGross does it work as expected?
Did as you said and It is now working correctly,thank you very much for your help