Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 石头布剪刀窗。警报不工作_Javascript_Html - Fatal编程技术网

Javascript 石头布剪刀窗。警报不工作

Javascript 石头布剪刀窗。警报不工作,javascript,html,Javascript,Html,我做了一个石头剪刀游戏,但是window.alert不起作用,所以用户看不到他们是否赢了!我该如何解决这个问题? 这是我的JS: var userChoice = prompt("Do you choose rock, paper or scissors?"); var computerChoice = Math.random(); if (computerChoice < 0.34) { computerChoice = "rock"; } else if(computerCho

我做了一个石头剪刀游戏,但是window.alert不起作用,所以用户看不到他们是否赢了!我该如何解决这个问题? 这是我的JS:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2) {
 if(choice1 === choice2) {
    return "The result is a tie!";
      window.alert("Wait what. We tied?");
    }

    else if(choice1 === "rock") {

        if(choice2 === "scissors") {
            return "rock wins";
              window.alert("What? Why u crush my scissors :<. I guess you won!");
        }
        else {
            return "paper wins";
            window.alert("Got a present for you! Just kidding lol its a rock packed in paper. Imma throw it at you and you will die.");
        }
    }
    if(choice1 === "paper")
        if(choice2 ==="rock"){
            return "paper wins";
            window.alert("Your paper, Vs my Rock! Hah! I won!");
        }
    if(choice1 === "scissors"){
        if(choice2 ==="rock"){
            return "rock wins";
              window.alert("I just crushed your scissors fam. I won. ezpz take the L");
        }
    else{
        return "scissors wins";
          window.alert("You spooked m8? My scissors cut you in 326 pieces! >:D");
         }
    }
};
compare(userChoice,computerChoice);
var userChoice=prompt(“您选择石头、布还是剪刀?”);
var computerChoice=Math.random();
如果(计算机选择<0.34){
computerChoice=“rock”;
}else if(computerChoice程序无法访问window.alert()调用。当程序遇到return语句时,执行将返回到调用函数的位置。您必须将window.alert()调用移到每个return语句上方,以便在希望显示警报时调用它们

此外,在每个警报语句中使用“window.”是可选的。

程序无法访问window.alert()调用。当程序遇到return语句时,执行将返回到调用函数的位置。您必须移动window.alert()在每个return语句上方调用,以便在需要显示警报时调用它们


另外,使用“窗口”在每个警报语句中,都是可选的。

除了一个之外,返回在警报之前。返回会使您中断函数,其余的行不会运行,请尝试将它们全部切换。

除了一个,返回在警报之前。返回会使您中断函数,其余的行不会运行,请尝试将它们全部切换大约

你错过了一些

else
还有一些花括号

请修复您的缩进。

您缺少一些缩进

else
还有一些花括号


请修复缩进。.

无法访问警报,因为在调用它们之前,您有一个退出函数的return语句。您缺少一个大括号,需要另外一个大括号。一旦我正确缩进代码,这很容易发现

尝试:

var computerChoice=Math.random();
如果(计算机选择<0.34){
computerChoice=“rock”;

}else if(computerChoice警报无法访问,因为在调用它们之前有一个return语句,该语句退出函数。并且缺少一个花括号,需要额外的else,一旦我正确缩进代码,就很容易发现

尝试:

var computerChoice=Math.random();
如果(计算机选择<0.34){
computerChoice=“rock”;

}否则,如果(computerChoice,谢谢,它工作了;但是如果没有窗口,我将如何使用它。?我需要声明一个变量吗?或者我可以只声明一个alert?(或者.alert)而不需要声明一个变量。因为窗口是一个全局对象,所以可以调用alert()简而言之。在这里看到答案:。谢谢,它起作用了;但是如果没有窗口,我该如何使用它。?我需要声明一个变量吗?或者我可以只声明一个alert?(或者.alert)不需要声明一个变量。因为窗口是一个全局对象,所以可以调用alert()简而言之。请参见此处的答案:。此外,这在没有窗口的情况下工作。需要警报,只需警报。不需要变量。此外,这在没有窗口的情况下工作。需要警报,只需警报。不需要变量。