how to make a rectangle in javascript
snippet in html

draw rectangle on javascript canvas


var c = document.getElementById("myCanvas");

var ctx = c.getContext("2d");

ctx.rect(20, 20, 150, 100);


how to make a rectangle in javascript


const canvas = document.getElementById('pong') // first make a index . html with a canvas height and width and id of pong or whatever
// and then we have to get access to our context to draw on it
const context = canvas.getContext('2d')

// then you do...

context.drawRect(20, 20, 150, 150);
context.fillStyle = '#fff' // thats white!!

js draw square to canvas


// canvas context.fillRect(x, y, height, width);
ctx.fillRect(20, 20, 150, 100);

how to make a rectangle in javascript


	<meta charset="UTF-8">
	<script language="Javascript" type="text/Javascript" src="libraries/p5.js"></script>
	<script language="Javascript" type="text/Javascript" src="pong.js" defer></script>
		<style> body {padding: 0; margin: 0;} </style>
	<canvas id="pong" width="600" height="400"></canvas>