Hey everyone! I recently built a simple Rock-Paper-Scissors game for the web, but I've run into an issue trying to run my JavaScript code because I have Node.js installed. When I try to run my script, I get a 'Reference Error: document is not defined' error. I've looked online, and it suggested installing a DOM manipulation library, which I did, but I'm still stuck. Can anyone help me figure out what's going wrong or how to properly run my project? Thanks!
1 Answer
You basically have two main options for running JavaScript: 1) Write your script in an HTML file and run it in a web browser or 2) Execute it with Node.js from the terminal. It seems like you want to run your script as a part of a webpage (option 1) but are trying to do it in Node.js (option 2), which won't work. If you want to run JavaScript for web projects, make sure to do it in the browser!
Just to add on that, if you're looking to create a desktop app experience with your web project, check out Electron! It might fit what you’re looking for.