function playRound(playerSelection, computerSelection) {
if (playerSelection == computerSelection) {
console.log("its a tie")
} else if (playerSelection == "rock" && computerSelection == "paper") {
return "you lose"
} else if (playerSelection == "rock" && computerSelection == "scissors") {
return "you win"
} else if (playerSelection == "paper" && computerSelection == "scissors") {
return "you lose"
} else if (playerSelection == "paper" && computerSelection == "rock") {
return "you win"
} else if (playerSelection == "scissors" && computerSelection == "rock") {
return "you lose"
} else if (playerSelection == "scissors" && computerSelection == "paper") {
return "you win"
}
}
let playerSelection = parseInt(prompt("input rock paper or scissors"))
let computerSelection = Math.random();
if (computerSelection < 0.34){
computerSelection = "rock"
} else if(computerSelection <=0.67){
computerSelection = "paper"
} else {
computerSelection = "scissors"
}
console.log(playRound(playerSelection, computerSelection))
I know its probably not the best method but i thought it should get the job done, any help is useful as i don’t know where the mistake can be, thank you. I looked at some other posts but couldn’t find the solution. This is my first post so if there is some info missing or something just let me know!
2
Answers
There are a few issues,
Try the following
You shouldn’t be using
parseInt
because the user will be entering string data, not numbers.You also need to move some of your
console.log()
statements around a bit, but other than that, you’re good to go!