I copied this code into gedit and saved it as 'Codecademy Rock Paper Scissors.js'. It worked on Codecademy, but as soon as I try to open it, it says that there is an error on line 1, char 1: object expected. What is the problem?
How do I tell it to run the code?
You use it via the script tag, either like this:
<script> Here goes your code </script>
or like this:
What you can do as well is to press CTRL+U to see the source code of a web page to see how others do this. But better take the tracks before this because the source codes of bigger websites get kind of long with all the ads and stuff.
@haxor789 what would you say about running the script with nodejs instead of in a browser? Same way as one would run Python.
If @allotmentgarden is using gedit then they probably have easy access to node as well
Debian-based as an example just because they're a likely first distro:
# apt-get install nodejs $ echo "console.log('hello world')" > hello.js $ nodejs hello.js hello world
I know JS is meant to run in the browser and all that. But if the code has nothing to do with the browser, then doesn't this make sense?
Googling "error on line 1, char 1: object expected" suggests that internet explorer is being used though. nodejs can be installed on windows as well, but it's more trouble than just typing in a single command so then one might as well just stick with the browser