canvas html rectangle code example
Example 1: 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 2: 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");
Example 3: javascript rect
ctx.fillRect(20, 20, 150, 100);