Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
Error on canvas
Why doesn't the following code work??? The id is correct on the HTML file const canvas = document.getElementById("c"); console.log(canvas); canvas.height = innerHeight; canvas.width = innerWidth; canvas.style.backgroundColor = "black"; var c = canvas.getContext("2d"); c.beginPath(); c.arc(50, 50, 100, 0, 2*Math.Pi,false); c.strokeStyle = "orange"; c.stroke();
2 Respostas
+ 1
Try wrapping the code inside an onload event listener on window. Something like
window.onload = () = { code... }
The script on Sololearn loads before the all HTML is parsed so the element with id "c" might not exist at the time your code runs.
+ 2
It was the problem indeed now it works just fine
Thank you a lot