WebStorm: prompt is not defined
Hi everyone,
I'm new to programming in general and have been using WebStorm while I teach myself JavaScript. I understand the why I got the error message I referenced in the title. It's a method of the DOM Window object. My question is, how do I debug if I want to use DOM methods in my script? Is there a library that I need?
I know this is a rookie question, but any clarity on this would be much appreciated.
Thanks!
Tom
Please sign in to leave a comment.
What does the error look like exactly? Is it a runtime error (shown when you run/debug your script), or a warning shown in editor? Please attach a screenshot
I have the same problem: this is the return of the console:
ReferenceError: prompt is not defined
at Object.<anonymous> (C:\Users\Admin\WebstormProjects\michael.geerts\JavaScript\JavaScript 6 oefeningen\Variables.j
s:1:12)
←[90m at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m
Process finished with exit code 1
window.prompt() is a function that web browsers implement, there is no such function in Node.js. And you must be running your file as a Node.js application - thus the issue. You can only prompt the user with client-side javascript, i.e. running in the browser via a tag in the rendered HTML, not the Javascript API engine running on the server.
In order to run your code, you need to create
.htmlfile and add a reference to your.jsto it - likeand then run this code in browser by right-clicking this
.htmlfile and choosing either Run or Debug from context menu.Or, if you like to run your code with Node.js, you need changing it accordingly. For example, you can use process.stdin or readline to read entered value from console