JS Scopes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

30th Dec 2018, 11:32 AM
Zakariya
Zakariya - avatar
4 Answers
30th Dec 2018, 12:56 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
0
Just make 'ctx' a global variable.
30th Dec 2018, 11:40 AM
Ulisses Cruz
Ulisses Cruz - avatar
0
Your last question already gave the same answer. https://www.sololearn.com/Discuss/1638913/?ref=app Move var ctx to global scope
30th Dec 2018, 12:09 PM
Calviղ
Calviղ - avatar
0
I moved it to a global scope but the canvas itself did not work anymore
30th Dec 2018, 12:43 PM
Zakariya
Zakariya - avatar