I've been working on a simple javascript function for hours. The intention is that 2 comments are displayed under an article by default, and that 5 are added each time you click on a button.
This is my code:
<div id="reaction1">Comment 1</div>
<div id="reaction2">Comment 2</div>
<div id="reaction3">Comment 3</div>
<div id="reaction4">Comment 4</div>
<p onClick="reactionsfunction()">More reactions</p>
<script>
var reactionsload = 2;
function reactionsfunction(){
reactionsload = reactionsload + 5;
}
var x = document.querySelectorAll("div[id^='reaction']");
for (var i = 0; i < reactionsload; i++) {
x[i].style.display = "block";
}
</script>
The for loop works perfectly, but the variable is not updated. How do I get the function to update the condition in the for loop by the function?