+ 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>
2 Antworten
+ 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
}
+ 1
thank you