#!TypeError: Cannot read properties of null (reading 'value')

8 messages · Page 1 of 1 (latest)

teal tartan
#

Good evening everyone,
I am working on the "Solo Project Unit Converter" and I'm currently stumbled on getting my conversion button working.

Here is the my code:
https://scrimba.com/scrim/co4794db6bbcefb555c2bf5b6

May anyone please assist and help explain what I'm doing wrong.

Thank you 🙂

slim nest
#

Here's the long explanation for why this matters:

Programs (for the most part) read code line by line top to bottom, so what happens here is the program reads through the html file top to bottom and renders all that out to the screen, THEN reads the javascript file from top to bottom. 

The reason why you want the script tag at the end of the body is because if your javascript file has something like document.getElementById(btn), you don't want the program to try to run that code before the button has been rendered to the screen. After all, how can the javascript do anything with that button if the button doesn't exist yet?

The exception to this is if you give the script tag the defer attribute and place it in the head. Doing this is basically saying to the program "I'm placing this script tag here, but don't do anything with it until you've finished rendering the html to the screen"
teal tartan
#

It solved every problem. Incredible.

slim nest
#

👍

shut cypress
slim nest