+ 1

What is wrong with this code

<html> <head> </head> <body> <script type="text/javascript"> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.font = "30px Arial"; ctx.fillText("Hello World",10,50); </script> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #ffaagg;"> </canvas> </body> </html>

10th Feb 2019, 4:53 PM
Hussein Adam
Hussein Adam - avatar
2 Respostas
+ 4
The code is executed before the canvas element is created, change that and move the canvas before the script element, or put all the javascript code here: window. onload = () => { //Your code here }
10th Feb 2019, 4:57 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 1
thank you
11th Feb 2019, 2:23 PM
Hussein Adam
Hussein Adam - avatar