Step Three: Use the error console. When you can't work out just why the code isn't doing what you expect then add console.log() calls into the code to display the values that particular fields hold part way through the processing. With the browser error console open you can then see what values get written to the console log as the statements are run without the execution of the code being interrupted.
In most modern browsers the F12 key will open the browser debugging tools for you (including the error console).
So before you post your code on a forum asking for help in getting it to work, why not at least try some of the steps for actually testing your code. Proper testing will at least give you more information that you can include in your post. Even if you don't understand what the error messages mean, others will be more easily able to help you to work out why your code isn't working if you tell them what error messages you get from these testing steps. Not providing this information means that you are expecting others to perform these steps for you (assuming that the cause isn't so obvious that they spot it immediately just by looking at the code - something always much easier for anyone other than the original author to do). Even if you can't work it out yourself from the messages that these tests produce, including the messages in your request for help also demonstrates that you have at least made an effort to try to figure it out for yourself making it far more likely that others will help.
This article written by Stephen Chapman, Felgall Pty Ltd.