爲什麼我的程序無法正常工作?Javascript Rock Paper Scissors
我的Math.random有什麼問題嗎?
「你選擇石頭,紙還是剪刀?」
「你選擇石頭,紙還是剪刀?」
「你選擇石頭,紙還是剪刀?」
//////////////////////////////
var userChoice = prompt("Do you choose Rock, Paper or Scissors?")
var computerChoice = Math.random();
//======================================
if(computerChoice <= 0.33)
{
computerChoice = "Rock";
}
else if(computerChoice <= 0.66)
{
computerChoice = "Paper";
}
else
{
computerChoice = "Scissors";
}
console.log("Computer: " + computerChoice);
//==========================================
var compare = function(choice1, choice2)
{
if(choice1 === choice2)
{
return "The result is a tie!";
}
else if(choice1 === "Rock")
{
if(choice2 === "Scissors")
{
return "Rock wins";
}
else
{
return "Paper wins";
}
}
else if(choice1 === "Paper")
{
if(choice2 === "Rock")
{
return "Paper wins";
}
else
{
return "Scissors wins";
}
}
else if(choice1 === "Scissors")
{
if(choice2 === "Paper")
{
return "Scissors wins";
}
else
{
return "Rock wins";
}
}
};
compare();