Most of the time you want to put your script tags at the end of the body. When you put the script tag in the head and try to access an element in the document it will be undefined because the page has not loaded yet.
<!DOCTYPE html> <html> <head> <link rel='stylesheet' href='style.css'/> </head> <body> <canvas id = "canvas" width = "200" height "200"> </canvas> <script src='script.js'></script> </body> </html>
If you do put the script in the head you will need some sort of document onload event listener.
Thank you very much. It worked!