Uncaught TypeError: Cannot read property 'getContext' of null

The error basically means that the HTML and the JavaScript code aren't cooperating properly, or simply that you haven't loaded the script correctly.
Try this:

function init() {
  // Run your javascript code here
}

// Run the 'init' function when the DOM content is loaded
document.addEventListener("DOMContentLoaded", init, false);

Hope this helps.


The answer is in the comments just after the question! Someone else also posted it as an answer a bit below, but all credits to: @elclanrs

"Right, so the canvas doesn't exist yet. Load the script after the canvas element. – elclanrs Sep 13 '14 at 22:43"