I'm building a Rock, Paper, Scissors game using JavaScript and HTML. I made the game work in the console, and now I'm just adding a UI to it. I'm having an issue setting the playerChoice
variable using HTML buttons (I was using a prompt before, but that's not very user-friendly).
What I've tried doing is making a function that is supposed to set playerChoice
to whatever button is clicked. I set the onClick
method for my buttons to run this function, and use the button's value as an input parameter. However, I'm getting "input not defined errors" when I test this.
let playerChoice = ""
function setPlayerChoice(choice){
playerChoice = choice;
}
<button class="button" id="btnRock" onClick=setPlayerChoice("rock")>Rock</button>
<button class="button" id="btnPaper" onClick=setPlayerChoice("rock")>Paper</button>
<button class="button" id="btnScissors" onClick=setPlayerChoice("scissors")>Scissors</button>