为游戏获胜者添加弹出框

时间:2019-05-18 04:37:03

标签: javascript function popup

我一直在尝试为我的剪刀石头布游戏添加一个弹出框,以便该程序在游戏结束时显示获胜者。我有一个功能文件和一个包含主要代码的文件。

我曾尝试研究弹出框,但最合适的警报是。我还尝试了一个按钮,但它们都无法使用。我尝试过的行如下:

input type =“ button” onclick =“ getWinner(userButton,compChoice)” value =“ Winner” />

alert(getWinner());

<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta 
charset="UTF-8">
<title>my game</title>
<script src="rsp.js" type="text/javascript"></script>   
</head>

<body>
Rounds to Play: <input id="ROUNDS_TO_PLAY"><br>
<input type="button" id="START_GAME" value="Start!" onclick="startGame()">
Rounds Remaining: <input id="ROUNDS_REMAINING"><br><br><br>

<input type="button" id="ROCK_CHOICE" value="Rock" onclick="userChoice('ROCK')">
<input type="button" id="PAPER_CHOICE" value="Paper" onclick="userChoice('PAPER')">
<input type="button" id="SCISSORS_CHOICE" value="Scissors" onclick="userChoice('SCISSORS')">


<br>
User Chose: <input id="USER_CHOICE_OUTPUT" type="text" disabled="true"><br>
Computer Chose: <input id="COMPUTER_CHOICE_OUTPUT" type="text" disabled="true">
  <input type = "button" onclick = "getWinner (userButton, compChoice)" value="Winner" />
  alert(getWinner()); 



//in a separate file is this function
function getWinner (userButton, compChoice)
{
if (userButton == compChoice )
{
    return "TIE";
}
if (userButton == "ROCK")
{
    if (compChoice == "SCISSORS")
    {
        return "USER WINS";
    }
    else 
    {
        return "COMPUTER WINS"
    }
}
if (userButton == "PAPER")
{
    if (compChoice == "ROCK")
    {
        return "USER WINS";
    }
    else 
    {
        return "COMPUTER WINS"
    }
}
if (userButton == "SCISSORS")
{
    if (compChoice == "PAPER")
    {
        return "USER WINS";
    }
    else 
    {
        return "COMPUTER WINS"
    }   }

我希望输出是“ Computer wins”或“ User Wins”,但我希望它在弹出框中,因此一旦游戏结束,弹出框就会出现并且我没有输出

0 个答案:

没有答案