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```
Wraithiia
  • 1
  • 1
  • 1
    Does this answer your question? [ReferenceError: document is not defined (in plain JavaScript)](https://stackoverflow.com/questions/24647839/referenceerror-document-is-not-defined-in-plain-javascript) – Reyno Nov 16 '20 at 08:52

1 Answers1

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).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 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. – Wraithiia Nov 16 '20 at 09:16