'I've tried setting up my Canvas in JavaScript and it isn't working

I've restarted about 5 times and it's not working. I'm trying to set up my canvas. The first part is the code in the js file and the second code is what I put in the HTML file.

JS:

var canvas;
var ctx;
var w = 1000;
var h = 600;


function setUpCanvas(){
    canvas = document.querySelector("#myCanvas");
    ctx = canvas.getContext("2d");
    canvas.width = w;
    canvas.height = h;
    canvas.style.border = "5px dotted orange";
   

HTML:

 <!DOCTYPE html>
<html>
    <head>
        <link rel ="stylesheet" type = "text/css" href = "m4.css">
    </head>
    <body>
        <div id = "container">
            <h1> module 4 : arrays and loops</h1>
            <canvas id = "myCanvas"></canvas>
        </div>
        <script src = "m4.js"></script>
    </body>
</html>


Solution 1:[1]

Simple answer, it works. for proof, visit

https://loading.hermanboxcar5.repl.co

ok if you do ctrl u on that website it will give you the code you did (except my js file is named script.js). My best guess so far is after the last line of your js put a }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hermanboxcar