Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one use "prompt" and "alert" javascript commands in webstorm?

When i try to use prompt or alert to get user input in webstorm, I get an error:

   answers[i] = prompt(allQuestions[i].question)
                ^

ReferenceError: prompt is not defined

As far as I know, prompt and alert are fine functions in javascript. Could it be because I am running the code in the console? If so, how do I set variables to user inputted strings (i.e. prompt function)? If not, what's going wrong and how do I fix it?

like image 777
Goodword Avatar asked Oct 17 '14 03:10

Goodword


1 Answers

By running code in console, do you mean that you run it with Node.js? But 'prompt' (as well as 'alert', etc.) can't be used in server-side scripts executed by Node.js. 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.

like image 151
lena Avatar answered Sep 29 '22 06:09

lena