<script>
let n = document.getElementById("number")
let colors = document.getElementById("color")
function drawRectangle() {
let a = n.value
let b = colors.value
document.getElementById("output").innerHTML = "Every " + a + " rectangle is " + b;
myShape();
}
function myShape() {
let canvas = document.getElementById("myCanvas");
let ctx = canvas.getContext("2d");
let x;
let y;
ctx.beginPath();
ctx.lineTo(0,0);
ctx.lineTo(10,0);
ctx.lineTo(10,10);
ctx.lineTo(0,10);
ctx.lineTo(0,0);
ctx.fillStyle = "red";
ctx.fill();
ctx.stroke();
ctx.strokeRect(0,0,10,10);
ctx.strokeRect(10,0,10,10);
ctx.strokeRect(20,0,10,10);
ctx.strokeRect(30,0,10,10);
ctx.strokeRect(40,0,10,10);
ctx.strokeRect(50,0,10,10);
ctx.strokeRect(60,0,10,10);
ctx.strokeRect(70,0,10,10);
ctx.strokeRect(80,0,10,10);
ctx.strokeRect(90,0,10,10);
ctx.strokeRect(100,0,10,10);
ctx.strokeRect(110,0,10,10);
ctx.strokeRect(120,0,10,10);
ctx.strokeRect(130,0,10,10);
ctx.strokeRect(140,0,10,10);
ctx.strokeRect(150,0,10,10);
ctx.strokeRect(160,0,10,10);
ctx.strokeRect(170,0,10,10);
ctx.strokeRect(180,0,10,10);
ctx.strokeRect(190,0,10,10);
ctx.strokeRect(200,0,10,10);
ctx.strokeRect(210,0,10,10);
ctx.strokeRect(220,0,10,10);
ctx.strokeRect(230,0,10,10);
ctx.strokeRect(240,0,10,10);
ctx.strokeRect(250,0,10,10);
ctx.strokeRect(260,0,10,10);
ctx.strokeRect(270,0,10,10);
ctx.strokeRect(280,0,10,10);
ctx.strokeRect(290,0,10,10);
ctx.strokeRect(300,0,10,10);
}
document.getElementById("display").onclick = drawRectangle;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> CPSC 1045 Midterm 2 Practical Exam </title>
</head>
<body>
<h1>Let's Display Some Rectangles</h1>
<p>This application will diplay a series of rectangles on the screen, filling every Nth rectangle with the specified colour</p>
<p>Enter a number for N:<input type="number" id="number" max="30"></p>
<p>Enter the color: <input type="color" id="color"></p>
<button id="display">Display</button>
<p id="output">Output here</p>
<canvas id="myCanvas" height="50" width="300" style="border: 1px solid black">