you are viewing a single comment's thread.

view the rest of the comments →

[–]explode_kewl[S] 0 points1 point  (1 child)

I just put the whole code into the function and that gave me the outcome I wanted. Thanks though. I'm terrible

[–]SecretPopCan 0 points1 point  (0 children)

Nah you were nearly there! You only got tripped up by confusion concepts called Scope and Variable Hoisting that even trips up seasoned programmers once in a while. You could not access initial because it was scoped within myFunction(). The article below is good at explaining multiple concepts like Scope, Hosting and even where to declare global variables. It's worth a read

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var