javascript how to draw a rectangle code example
Example 1: js draw square to canvas
ctx.fillRect(20, 20, 150, 100);
Example 2: how to make a rectangle in javascript
const canvas = document.getElementById('pong')
const context = canvas.getContext('2d')
context.drawRect(20, 20, 150, 150);
context.fillStyle = '#fff'
Example 3: draw rectangle on canvas javascript
ctx.fillStyle = "(enter color)";
ctx.fillRect(x, y, width, height);
var canvas = document.getElementById("(enter canvas's id)");
var ctx = canvas.getContext("2d");