I am new to javascript. And I can't understand why the codes not working the same. this is the canvas :
var canvas = document.getElementById("gameScreen");
var context = canvas.getContext("2d")
context.fillRect(20, 20, 20, 20);
#gameScreen {
background-color:coral;
width:200px;
height:200px;
}
<!--<canvas id = "gameScreen" width= "200" height= "200" style="background-color:coral"></canvas> -->
<canvas id = "gameScreen"></canvas>
this is another canvas :
var canvas = document.getElementById("gameScreen");
var context = canvas.getContext("2d");
context.fillRect(20, 20, 20, 20);
#gameScreen {
background-color:coral;
}
<canvas id="gameScreen" width="200px" height="200px"></canvas>
why the first one is not working as the second one??