In the old days, not declaring a variable made it a global. Currently it makes you a bad programmer. In "strict" mode, it makes it an error. Declare your variables. Don’t be bad.
Line 17 of your code happens when the script is run. Line 14 happens much later, during a click.
You can’t access a value that hasn’t been set yet.
JΛ̊KE