I am fairly new to coding and I'm currently doing the Odin Project. One of the projects from there asks to build a rock, paper, scissors game. I'm not trying to do anything fancy, so I'm just having the result show in the console. Every time I run the code and input any response all that returns is "it's a draw" every time. Here is the code:
let playerChoice = prompt("Enter Rock, Paper, or Scissors:").toLowerCase();
let computerRandom = Math.floor(Math.random() * 3 + 1);
function computerRand() {
if (computerRandom === 1) {
return "paper";
} else if (computerRandom === 2) {
return "rock";
} else if (computerRandom === 3) {
return "scissors";
}
};
computerRand();
function playRound(playerSel, computerPlay) {
let playerChoice = playerSel;
let computerRand = computerPlay;
if ((playerSel === 'rock' && computerPlay === 'scissors') || (playerSel === 'scissors' && computerPlay === 'paper') || (playerSel === 'paper' && computerPlay === 'rock')) {
return "Player Wins";
} else if (computerPlay == playerSel) {
return "it's a draw";
} else if ((computerPlay === 'rock' && playerSel === 'scissors' || computerPlay === 'scissors' && playerSel === 'paper' || computerPlay === 'paper' && playerSel === 'rock')) {
return "You lose";
} else {
return "That is not an option"
}
};
playRound();
console.log(playRound());
Aucun commentaire:
Enregistrer un commentaire