var name = prompt("enter your name");
i debugged it in VS CODE and in Node command prompt.Both are showing this error:
vs code error
node command prompt error:
please help me find the error.
nodeJS use Google’s V8 engine, although similar to the JS engine of the chrome browser, its not identical.
prompt is indeed part of the window object in your browser JS engine:
it does not exists in nodeJS.
Its important to understand what nodeJS is, what its used for. I would recommend you to do some research. Let me know if there are further questions you need help with
Also I tried running the command
npm install prompt -- save
it installed a json file but its still giving the same error.
Also I tried running the program on codecademy code editor and its a success.
So, this package:
Have you looked at the usage and the examples?
did you read my answer? I covered this, the codecademy courses uses the browsers JS engine, while nodeJS uses a different engine, and there are not the same thing…
this advice still stands
Its important to understand the tools you are using I know, this can be very overwhelming in the beginning.
Why not simplify matters for yourself? You have a browser installed on your computer (that seems a safe assumption ), you could use that to run your JS files? Then you don’t have this problems you are facing with nodeJS
don’t know if you learned html? Anyway, if you make two files (in the same directory/folder), one
<meta name="viewport" content="width=device-width">
and the other
a.js with your javscript code. If the JS file has a different name, make sure to change this line:
a.js to whatever you named your JS file
you can open the html file with your browser, then use the console (f12, then console tab) to run your JS code. Just refresh the page (f5 or ctrl + r) to rerun your JS code
or, if that is too much at the moment, you could use a site like jsbin:
there is a run button at the top right, maybe that is the easiest step
A zillion thanks for the help.