简体   繁体   English

找不到变量:提示

[英]Can't find variable: prompt

#!/bin/sh

//Rock, Paper, Scissors

var myChoice = prompt("Rock, Paper, or Scissors?");

var computerChoice = Math.random();

if (computerChoice >= 0 && computerChoice <= .33) 
{
    computerChoice === "rock";
}
else if (computerChoice >=.34 && computerChoice <= .67) 
{
    computerChoice === "paper";
}
else 
{
    computerChoice === "scissors";
};

I understand my code to be rudimentary, but I am just beginning with Javacript. 我知道我的代码是基本的,但是我只是从Javacript开始。 I am trying to run this code through the terminal and continue to get the error message "can't find variable: prompt." 我正在尝试通过终端运行此代码,并继续获取错误消息“找不到变量:提示”。 I am sure there is a simple explanation out there, but I can't seem to find it. 我敢肯定那里有一个简单的解释,但是我似乎找不到。

prompt() is for browsers. prompt()用于浏览器。 You should use the functions found here instead. 您应该改用此处找到的功能。

You cannot use the prompt function in terminal. 您不能在终端中使用提示功能。 It only works in browsers, as it causes a box to popup that the user enters something in. Put it in an html file, and it will work: 它仅在浏览器中有效,因为它会导致弹出一个框,供用户输入内容。将其放在html文件中,它将起作用:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        // your code goes here, minus that first comment.
        </script>
    </head>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM