Button to increment or decrement at random
Posted: 04 Dec 2020, 05:38
Quick question:
How can I set a button that can increment and/or decrement at random a number as it is clicked?
This is the code i have.
How can I set a button that can increment and/or decrement at random a number as it is clicked?
This is the code i have.
Code: Select all
<button id='tst_btn'>Change counter</button>
<h3 id='tst_count'>0</h3>
<script>
var counter = 0,
tst_count = document.getElementById('tst_count'),
tst_btn = document.getElementById('tst_btn');
tst_btn.addEventListener('click', ()=>{
//..code to increment or decrement at random ??
tst_count.innerText = counter;
});
</script>