如何在按下按钮后弹出提示?

时间:2015-12-22 20:05:19

标签: javascript html button

我已经尝试了一切,但我被卡住了。有人可以查看我的代码,看看我错过了什么吗?我正在制作一个摇滚,纸张,剪刀和#39;游戏。

var userChoice = prompt("Do you choose rock, paper, scissors, lizard, or spock?");

var computerChoice = Math.random();
if (computerChoice < 0.16) {
    computerChoice = "rock";
} else if(computerChoice <= 0.36) {
    computerChoice = "paper";
} 

else if(computerChoice <= 0.56){
    computerChoice = "scissors";
} 

else if(computerChoice <= 0.76){
    computerChoice = "lizard";
}
else {
    computerChoice = "spock";
}



var compare = function(userChoice, computerChoice) {
   if (userChoice === computerChoice) {
       return"It's a tie!"}

我有一个附加到js文件的html doc。我想在按下按钮后显示userChoice

0 个答案:

没有答案