I have just started on a new short game and i am trying to figure out how to make a reward when i reach a certain value I expect that the counter starts at zero, and each time the button is clicked it goes up by one, until it reaches 10, then the next time the button is pressed the counter should go up by 2. Instead, I find that clicking the button does not change the displayed count.
<!DOCTYPE html>
<html>
<body>
<p>
The button was clicked
<span class="total-clicks"></span>
times
</p>
<button id="btn1" onclick="addClick()">
Click Me!
</button>
<script type="text/javascript">
let clicks = 0;
let click_power = 1;
let reward_recevied = false;
function addClick() {
clicks = clicks + click_power;
if(clicks >= 10 && reward_received == false) {
click_power = click_power + 1;
reward_received = true;
}
}
function addClick() {
clicks = clicks + 1;
document.querySelector('.total-clicks').textContent
= clicks;
}
// Simulate click function
function clickButton() {
document.querySelector('#btn1').click();
}
</script>
</body>
</html>