Prompt is not defined?

my javascript file has an error
my filename=a.js

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 :slight_smile:

1 Like

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

1 Like

thanks for the reply.

Its important to understand the tools you are using :wink: I know, this can be very overwhelming in the beginning.

1 Like

yes indeed … I did javascript course on codecademy many times but nothing is entering my head.Programming is so volatile. :cry: :cry:
I know my doubts are stupid but Im just a beginner.I read it on stackoverflow that for debugging javascript file we should use node command prompt.The stackoverflow users said the same thing you are saying that codecadmey uses a different engine.Also they said that we should install the node packages(which i installed given above).Guess I will have to leave the solution ,sometimes in programming we don’t find a solution.

Why not simplify matters for yourself? You have a browser installed on your computer (that seems a safe assumption :stuck_out_tongue: ), 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 index.html:

<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>My javascript</title>
  <script src="a.js"></script>


and the other a.js with your javscript code. If the JS file has a different name, make sure to change this line:

<script src="a.js"></script>

from 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:,console

there is a run button at the top right, maybe that is the easiest step


yes this worked .But here’s one more thing I found out that console.log doesn’t run in VS code and Node command prompt.Yes if its a typescript file it runs but not a vanilla javascript code .Because as you mentioned which is correct that

A zillion thanks for the help.:+1::+1::+1: