Photos/screenshots of an error can be helpful, but it also helps to provide the complete code. Posting the code helps us help you better!
When you enter a code, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="/index.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>World Editor</title>
</head>
<body>
<h1>World Editor</h1>
<canvas class="myCanvas"></canvas>
<!-- script -->
<script>
myCanvas.width = 800;
myCanvas.height =800;
</script>
<script src="/index.js"></script>
</body>
</html>
What about it? Do you have a question?
the canvas is supposed to enlarge but nothing happens that the complete code.
What is myCanvas
supposed to be?
You have to get the element first, e.g. querySelector
.
<canvas class="myCanvas"></canvas>
<script>
const myCanvas = document.querySelector(".canvas");
myCanvas.width = 800;
myCanvas.height = 800;
</script>
Or, because id
s are global, you could also just add id="myCanvas"
to the canvas
element. But I really wouldn’t suggest relying on id
s being global, it is just confusing to read.
<canvas id="myCanvas" class="myCanvas"></canvas>
<script>
myCanvas.width = 800;
myCanvas.height = 800;
</script>
lemme try that idea hope it’s gonna work fine