[ad_1]
Recreation Growth Stack Trade is a query and reply website for skilled and impartial recreation builders. It solely takes a minute to enroll.
Anyone can ask a query
Anyone can reply
The perfect solutions are voted up and rise to the highest
Requested
Considered
34 instances
<!DOCTYPE html>
<html>
<physique>
<p>
The button was clicked
<span class="total-clicks"></span>
instances
</p>
<button id="btn1" onclick="addClick()">
Click on Me!
</button>
<script sort="textual content/javascript">
let clicks = 0;
let click_power = 1;
let reward_recevied = false;
operate addClick() {
clicks = clicks + click_power;
if(clicks >= 10 && reward_received == false) {
click_power = click_power + 1;
reward_received = true;
}
}
operate addClick() {
clicks = clicks + 1;
doc.querySelector('.total-clicks').textContent
= clicks;
}
// Simulate click on operate
operate clickButton() {
doc.querySelector('#btn1').click on();
}
</script>
</physique>
</html>
$endgroup$
1
If you wish to enhance the primary 10 instances the variable clicks + 1, and after 10, clicks + 2 it’s essential guarantee that the names of the variables within the code are “reward_received” in all places and write the code for the addClick() operate as soon as.
In your code you overwrite addClick() operate by writing it a second time.
You may view errors in your js for those who open html file within the browser by urgent f12.
Right here might be the code you wished:
<!DOCTYPE html>
<html>
<physique>
<p>
The button was clicked
<span class="total-clicks"></span>
instances
</p>
<button id="btn1" onclick="addClick()">
Click on Me!
</button>
<script sort="textual content/javascript">
let clicks = 0;
let click_power = 1;
let reward_received = false;
operate addClick() {
clicks = clicks + click_power;
if(clicks >= 10 && reward_received == false) {
click_power = click_power + 1;
reward_received = true;
}
doc.querySelector('.total-clicks').textContent = clicks;
}
</script>
</physique>
</html>
$endgroup$
You need to log in to reply this query.
Not the reply you are searching for? Browse different questions tagged .
lang-js
[ad_2]