So, I found an interesting pattern and I want to do an automated program for different numbers. In the program, you can input n
and m
, which aren't so important for now. The thing is, I cannot draw on the canvas. I am wondering what I'm doing wrong. This is the code:
<!DOCTYPE html>
<html>
<head>
<title>oof</title>
<meta charset="UTF-8">
<script>
function lines(n, m) {
var canvas = document.getElementById("theCanvas");
var c = canvas.getContext("2d");
var cy = n * m;
var cx = 1;
c.moveTo(cx, cy);
c.lineTo(cx, cy + 5);
c.stroke();
}
lines(1);
</script>
</head>
<body>
<canvas id="theCanvas" height="32767" width="32767" />
</body>
</html>
Uncaught TypeError: Cannot read property 'getContext' of null
at lines (hmm.html:9)
at hmm.html:20
` tag.
– T.J. Crowder Feb 28 '19 at 18:37