0
Hi, I’m writing a page with a Paper Stone or Scissors game. And I would like the user to be able to choose between the three options through three buttons, which when clicked call a function that assigns a value the variable relative to the user’s move, and then performs comparisons to know who won (Computer or User). My problem is that I can’t get the variable to receive the values equivalent to plays using the functions.
Note: My algorithm to compare the moves of both the PC and the User is working, so I didn’t post along.
var a = 0;
function Pedra() {
return a = 1;
}
function Papel() {
return a = 2;
}
function Tesoura() {
return a = 2;
}
if (a == 1) {
alert("pedra");
}
if (a == 2) {
alert("Papel");
}
if (a == 3) {
alert("tesoura");
}
<div>
<div>
<button type="button" onclick="Pedra()">Pedra</button>
</div>
<div id="papel">
<button type="button" onclick="Papel()">Papel</button>
</div>
<div id="tesoura">
<button type="button" onclick="Tesoura()">Tesoura</button>
</div>
</div>