0
Why is that my JavaScript code doesnot run as expected?
This happens especially when I try manipulating html elements from JavaScript. Below is some example of code like that. Please help me find the problem. https://code.sololearn.com/WcpzYPFy62qs/?ref=app
2 Answers
+ 3
It's because you declared the variable for the canvas before the page loaded, so it became undefined.
You should do it like this:
window.onload = () => {
//your code here
}
0
Thank you Airree.
It worked like a charm