In my code, I am getting only black canvas of defined width and height. And Red and white is not rendering on screen.
Thanks in advance.
var canvas;
var canvasContext;
var ballx = 50;
window.onload = function() {
canvas = document.getElementById('gameCanvas');
canvasContext = canvas.getContext('2d');
drawCanvas();
drawCanvasRed();
// drawCanvas();
}
function drawCanvas() {
canvasContext.fillStyle = 'black';
canvasContext.fillRect(0, 0, canvas.width, canvas.height);
canvasContext.fillStyle = 'white';
canvasContext.fillRect(225, 200, 50, 25);
};
function drawCanvasRed() {
canvasContext.fillStyle = 'red';
canvasContext.fillRect(ballx, 200, 50, 25);
}
#gameCanvas {
width: 500px;
height: 500px;
}
<canvas id="gameCanvas"></canvas>