0

Context 2d?

Hello, the web setup in Sololearn is html5, correct? I tried making a canvas context, and set up a code like this: const canvas = document.getElementById("canvas"); const screen = canvas.getContext("2d"); But it throws a typeError on getContext?

25th Dec 2023, 6:38 PM
Truls Nilsen
Truls Nilsen - avatar
2 ответов
+ 2
It is probably the load problem. To fix it, use this: window.onload = () => { // Rest of code here }
25th Dec 2023, 7:53 PM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
+ 1
Link your code. You can only get the canvas once the html body is loaded.
25th Dec 2023, 7:22 PM
Lisa
Lisa - avatar