[ For Beginner's ] Why is my code not working?

For HTML, CSS and JavaScript beginners.

I have been there waiting and worrying about why the code is not working.

And while working my way out to make it work, I came across the following things that needs attention.

  1. Go for syntax ( { ; Very common mistake is to miss the braces, brackets, commas and semicolons.

  2. Go for how variables are connected to each other. Are all functions and variables linked correctly at places? From HTML to JavaScript, is everything connected to each other as you intended to be?

  3. Run through logic. Do short tests. Unit tests for logical statements written. For example write console log at different places and see where they are executed and where they refuse to enter.

  4. Do a dry run or logical run for the said input and try to understand with console logs whether it is entering every logical statement and executing it correctly.

  5. Go to Inspect Element and check if any errors are seen in console. You many find errors pointed out mentioning the line numbers. Check them why are they highlighted as errors.

  6. Sometimes our logic works well for an input but may not work correctly for other input. We need to define additional things to make everything work.

  7. I left a project took up another and when I came back some things clicked well. Give time and stare at your code. I stared it long enough to see what I was avoiding to see.

  8. I was initially rushing to see the finished logic but then slowed down to understand how it works at every stage. Because how I think it works is very different from how it works

Go through the process and it will teach you so much about how everything works under the hood. If you get tired try it next day. If you cannot figure out then probably ask what logic is not working correctly. What logic is incorrectly assumed or knowledge of data types is not rightly understood.

Read your errors. Learn from them.