javascript “prompt is not defined” Reference Error

后端 未结 1 1201
别那么骄傲
别那么骄傲 2020-12-21 07:25
(function() {
    var random_num = Math.floor(Math.random()*10) + 1;
    var input_num = prompt(\"Guess the number between 1 and 10\");
    if (input_num < 1 || i         


        
相关标签:
1条回答
  • 2020-12-21 08:03

    Assuming you're using JSHint in WebStorm, set Preferences > Languages & Frameworks > JavaScript > Code Quality Tools > JSHint > Environments > Browser to true

    Screenshot of WebStorm settings

    Update: Also, as mentioned earlier, for good code you should use window.prompt, just so it's clear you're using the built in browser prompt rather than a custom function etc... (the same goes for alert, so use window.alert)

    Finally, unrelated to the question, but something I noticed - it's good practice to use the === operator. There are a million articles online explaining why :)

    0 讨论(0)
提交回复
热议问题