我需要使用表单,因此userChoice是输入,而computerChoice是输出。我的代码只能在提示中使用,但不能在表单中使用此外,我需要再次播放代码,因为它要求用户再次播放,但它不会重新加载游戏,你能帮忙吗?
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);
do{
choice1 = userChoice;
choice2 = computerChoice;
function compare(choice1, choice2){
if(choice1===choice2){
return ('The result is a tie!');
}
if(choice1==="rock"){
if(choice2==="scissors"){
return('Rock wins!');
}else{
return('Paper wins!');
}
}
if(choice1==="paper"){
if(choice2==="rock"){
return('paper wins!');
}else{
return('Scissors wins!');
}
}
if(choice1==="scissors"){
if(choice2==="rock"){
return('Rock wins!');
}else{
return('Scissors wins!');
}
}
}
console.log(compare(userChoice,computerChoice));
alert(compare(userChoice,computerChoice));
//do something usefull...
}while(prompt("Play again? (Y/N) Or just click the Rock Paper Scissors tab")=Y);
</script>