0

So I am using Derek Banas' Javascript tutorial and I'm getting this reference error.

Help??

document.addEventListener('DOMContentLoaded', SetupCanvas);
^

ReferenceError: document is not defined
    at Object.<anonymous> (c:\Users\kjkta.DESKTOP-AVBUOR0\Repository\Tetris\TetrisBasic.js:33:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47```
1

1 Answer 1

1

That tutorial is intended for JavaScript running in a web browser, via an HTML document with a script element in it.

You are trying to run it with Node.js.

Node.js and browsers provide a different set of APIs on top of core JS. It is browsers that provide the document object (which represents the HTML document).

Sign up to request clarification or add additional context in comments.

1 Comment

So funny enough, this error came in tandem with an error that was remedied with node.js. I have tried running the current script by using the live server as well as just opening the HTML file in the browser and am not getting any tetrominoes to populate despite being at the halfway point where he stops to test the code. Going back through my script to see if I missed anything currently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.