Javascript 石头剪刀问题
作为课程的一部分,我正在为代码学院编写一个简单的石头剪刀脚本;我得到的每一个答案在最后都是警告(“摇滚乐赢了!”),不管我投入了什么;我做错了什么Javascript 石头剪刀问题,javascript,Javascript,作为课程的一部分,我正在为代码学院编写一个简单的石头剪刀脚本;我得到的每一个答案在最后都是警告(“摇滚乐赢了!”),不管我投入了什么;我做错了什么 var choice1 = prompt("Do you choose rock, paper or scissors?"); //-------------------------------------// var choice2 = Math.random(); if (choice2 < 0.34) { choice2 = "
var choice1 = prompt("Do you choose rock, paper or scissors?");
//-------------------------------------//
var choice2 = Math.random();
if (choice2 < 0.34) {
choice2 = "rock"
}
else if(choice2 <= 0.67) {
choice2 = "paper";
}
else {
choice2 = "scissors";
}
console.log(choice2)
//------ possible outcomes for the computer are above this comment-----------
compare = function(choice1,choice2){
//----------------------------------------
if(choice1 === "paper" & choice2 ==="paper"){
alert("The result is a tie!");}
if(choice1 === "rock" & choice2 ==="rock"){
alert("The result is a tie!");}
if(choice1 === "scissors" & choice2 ==="scissors"){
alert("The result is a tie!");}
//-possible outcomes for a tie are above this comment------------------------------
if(choice1 === "paper" & choice2 === "rock"){
alert("paper wins!");}
if(choice1 === "rock" & choice2 === "paper"){
alert("paper wins!");}
//-possible outcomes for paper & rock are above this comment------------------------
if(choice1 === "scissors" & choice2 === "rock"){
alert("rock wins!");}
if(choice1 === "rock" & choice2 === "scissors"){
alert("rock wins!");}
//-possible outcomes for a scissors & rock are above this comment--------------------
if(choice1 === "scissors" & choice2 === "paper"){
alert("scissors wins!");}
if(choice1 === "paper" & choice2 === "scissors"){
alert("scissors wins!");}
//-possible outcomes for a scissors & paper are above this comment--------------
}//<---End of compare function--//
var choice1=prompt(“您选择石头、布还是剪刀?”);
//-------------------------------------//
var choice2=Math.random();
如果(选择2<0.34){
choice2=“岩石”
}
否则如果(选择2使用&
表示“和”,而不是&
if (choice1 === "paper" && choice2 === "rock") {
...