【发布时间】:2017-11-27 03:57:08
【问题描述】:
我做了一个石头剪刀布游戏,但是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);
其他一切正常,但它只是打印到控制台。 感谢您的帮助
【问题讨论】:
标签: javascript html