admin管理员组文章数量:1405984
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?
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?
Share Improve this question edited Oct 21, 2014 at 16:00 Goodword asked Oct 17, 2014 at 3:21 GoodwordGoodword 1,64520 silver badges28 bronze badges 2- 1 What do you mean by "in webstorm" ? Is this in HTML page ? My guess is that you don;t have the "window" object. prompt is a function on the window object. This can happen when your programming environment is nodejs etc. – bhantol Commented Oct 17, 2014 at 3:36
- @bhantol probably hit the nail on the head, im guessing you don't have the global window object available in the IDE. You need the window to trigger window functions. If you add prompt('test') into your browser console it will work as expected. PS don't use an IDE for JS you have everything you need in any browser and you'll never see a JS developer using an IDE unless they are working on backend code thats non-javascript. – Josh Bedo Commented Oct 17, 2014 at 13:54
1 Answer
Reset to default 5By 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.
本文标签: How does one use quotpromptquot and quotalertquot javascript commands in webstormStack Overflow
版权声明:本文标题:How does one use "prompt" and "alert" javascript commands in webstorm? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744969245a2635135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论