return this.each(function(){
const $gameDiv = $("#rps_game");
let $image1, $image2, $imageCaption, html;
let gameAmount = 0;
setGameStart();
$(this).find("#gameAmount button").click(function(event){
event.preventDefault();
if (parseInt($(this).val()) == 1){
gameAmount = 1;
}else if(parseInt($(this).val()) == 3){
gameAmount = 3;
}else if(parseInt($(this).val()) == 5){
gameAmount = 5;
}
console.log(gameAmount);
setGameProperties();
});
$(this).find("#choices button").click(function(event){
event.preventDefault();
console.log("TEST");
});function setGameProperties(){
$gameDiv.empty();
html = ('<img src="images\\question.png" id="player1" alt="Item 1">\
<img src="images\\question.png" id="player2" alt="Item 2">\
<br>\
<h3 id="score">0 - 0</h3>\
<br>\
<div id="choices">\
<button type="button" id="1" value="1">Rock</button>\
<button type="button" id="2" value="2">Paper</button>\
<button type="button" id="3" value="3">Sissors</button>\
</div>');
$gameDiv.append(html);
$("img").css({
"width": settings.imageWidth,
"height": settings.imageHeight,
"border": settings.imageBorder,
"border-radius": settings.borderRadius
});
$gameDiv.css({
"text-align": "center",
});
};
function setGameStart(){
$gameDiv.empty();
html = ('<div id="gameAmount">\
<button type="button" id="1game" value="1">Best of 1</button>\
<button type="button" id="3game" value="3">Best of 3</button>\
<button type="button" id="5game" value="5">Best of 5</button>\
</div>');
$gameDiv.append(html);
};
})
}}(jQuery))
I cannot figure out why my second click function is not working. If I move the setGameProperties() from the first click function to outside of it then my second click function works but then it skips over the setGameStart() function and goes right to the setGameProperties(). Can anyone tell me the reason I cannot use setGameProperties() inside of my click function or how I could rewrite this code to work?