I having trouble understanding $(this)
, I made a version of rock, paper, scissors and applied jQuery for the user to choose a button choice against the computer. I was hoping someone can explain what $(this)
is referring to, is it the btn-primary
? The function is below and if you need the html it is in the codepen link. Also, the result is shown in the console.
https://codepen.io/anon/pen/VeLWKP
$(".btn-primary").on("click", function () {
userChoice = $(this).attr("id");
computerChoice = computerOptions[Math.floor(Math.random() * computerOptions.length)];
console.log(userChoice, computerChoice);
});