This is the code, now matter what I input as the input parameter in the play function, it alwats returns "You win, rock beats scissors."
function computerPlay() {
switch(Math.floor(Math.random() * 3) + 1) {
case 1:
return "rock";
break;
case 2:
return "paper";
break;
case 3:
return "scissors";
break;
default:
return "error1";
break;
}
}
let playerInput;
function startPlay() {
playerInput = prompt("Rock, paper, or scissors?");
play(playerInput, computerPlay());
}
function play(a,b) {
if(((a = "rock") && (b = "scissors")) || ((a = "paper") && (b = "rock")) || ((a = "scissors") && (b = "paper"))) {
alert(`You win, ${a} beats ${b}!`);
}else if(((a = "rock") && (b = "paper")) || ((a = "paper") && (b = "scissors")) || ((a = "scissors") && (b = "rock"))) {
alert(`You lose, ${b} beats ${a}`);
}else if(a == b) {
alert("It's a tie.");
}
}
Aucun commentaire:
Enregistrer un commentaire