0

Why I can't use getContext in soloLearn app while it work good in other software

Error occurs when I try to getContext https://code.sololearn.com/WjQ53ZnW68oc/?ref=app

7th Aug 2020, 12:05 PM
Jack Murimi Kavita
Jack Murimi Kavita - avatar
2 Réponses
+ 4
Wrap your js code inside the following function window.onload=function(){ } On sololearn for some reason js gets executed before Dom is loaded so therefore trying to get element that doesn't exist returns that error ,the above function stops js from getting excuted until HTML Dom is loaded
7th Aug 2020, 12:15 PM
Abhay
Abhay - avatar
+ 3
In SL the JavaScript code is executed before the page is loaded so the canvas element was not created yet. Either wrap your code in window.onload() or write your script in HTML section after the canvas.
7th Aug 2020, 12:15 PM
Aymane Boukrouh
Aymane Boukrouh - avatar