New course! Every coder should learn Generative AI!
Try a free lesson0
JS Scopes
I made a question about this a while ago but it never helped too much. In my code I have a function to make the canvas fit the output area no matter the size of your device. However If I try to use the canvas outside of that it doesn't work. Could someone edit whatever I have done and fix it as a few people have given solutions but when I implement them they do not work my code: https://code.sololearn.com/W07da4CrvrB7/#html
4 Answers
0
Just make 'ctx' a global variable.
0
Your last question already gave the same answer.
https://www.sololearn.com/Discuss/1638913/?ref=app
Move var ctx to global scope
0
I moved it to a global scope but the canvas itself did not work anymore