add error check for init function

checks to see whether a canvas element can be found in the body and if
not throws an error