For example, say I want a block of code to run after a certain event occurs a certain amount of times (let's suppose a button is pressed in the following example). Would I use something similar to an if statement such as the following:
if( //certain event occurs: document.getElementById('btn').clicked == true 5 times
) {
//block of code to run if button is clicked 5 times: output in p element
}
<button id="btn" type="button">click</button>
<p></p>
If there's a more practical way than an if statement, I'd like know, please, and thanks. However, if an if statement is the way to go (unless of course there's a more practical method), how would you have a block of code run after a certain event occurs per specified increment of times? Utilizing the html elemenets above:
var alpha = 0;
function addition() {
alpha = alpha + 1;
return alpha;
}
document.getElementById('btn').addEventListener('click', 'get_addition');
function get_addition() {
document.getElementsByTagName('P')[0].innerHTML = addition();
if( //document.getElementById('btn').clicked == true per 5 times
) {
//block of code to run per 5 button clicks outputted in p element;
//then return to outputting values in p element rendered by addition() until next 5th iteration;
}
}