I made this game using textbox, and everything worked ok, but I decided to make a modification and instead of typing I put the respective images to the jokenpô and the image that the user clicks will be compared and would return to the user who won, from start would be done on the alert itself. My problem is in picking up the user's option and assigning a variable and making that comparison. How can I do this?
$(document).ready(function(){
var choice = null;
//Gera a opção do computador
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "Pedra";
} else if(computerChoice <= 0.67) {
computerChoice = "Papel";
} else {
computerChoice = "Tesoura";
}
//Pedra
$('#pedra, #papel, #tesoura').on('click',function(){
if((computerChoice == choice) || (computerChoice == choice)||(computerChoice == choice))
alert("Empate");
else if (choice === "pedra") {
if (computerChoice === "tesoura")
alert("pedra vence");
else {
alert("papel vence");
}
}
else if (choice === "papel") {
if (computerChoice === "pedra")
alert("papel vence");
else {
alert("tesoura vence");
}
}
else if (choice === "tesoura") {
if (computerChoice === "pedra")
alert("pedra vence");
else {
alert("tesoura vence");
}
}
});
});