0
#!/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";
};

我理解我的代码是初级的,但我只是从 Javacript 开始。我正在尝试通过终端运行此代码并继续收到错误消息“找不到变量:提示”。我确信那里有一个简单的解释,但我似乎找不到它。

4

2 回答 2

0

prompt()用于浏览器。您应该使用此处找到的函数。

于 2013-03-12T00:56:14.423 回答
0

您不能在终端中使用提示功能。它仅适用于浏览器,因为它会弹出一个框,用户在其中输入内容。将其放入 html 文件中,它将起作用:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        // your code goes here, minus that first comment.
        </script>
    </head>
</html>
于 2013-03-12T00:56:37.223 回答