+ 9
Hi Zak, The variable ctx was declared inside a function therefore its scope is localised to it. You are trying to use that variable again globally (outside its current scope) This article may help you https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/
8th Jan 2018, 10:04 PM
jay
jay - avatar
+ 8
Either make ctx global in scope or create a new variable ctx (which may be confusing for the reader, I would call it something else) If you want to make it global, at the top of the js put var ctx; that way there is little editing to do.
8th Jan 2018, 10:21 PM
jay
jay - avatar
+ 8
visph is correct.
8th Jan 2018, 10:28 PM
jay
jay - avatar
+ 3
Anyway, 'ctx' variable should be accessed only after init() was executed (in which 'ctx' is defined) ^^ I suggest to move the lines using 'ctx' to draw in canvas inside your init() function ;)
8th Jan 2018, 10:25 PM
visph
visph - avatar