Your code was right, you just forgot the
Here's a working repl
You'll notice I've added a couple more arguments, those are just to resize the image.
<img> element, and all that just to draw an image.
So if you plan to do anything that involves a canvas, I highly recommend p5.js. It's super intuitive and it abstracts away everything wrong with the canvas API, and there's so much you can do with it. There's also the youtube channel called Coding Train. He's got really nice videos on p5.js, and it's frankly quite hard not to get inspired watching some of his videos.
I hope this helped!