Generating errors using Javascript