I made a JavaScript array randomizer and it show the elements one at a time with interval. I want to make them show one at a time without the interval, but with button. When I click the button it shall switch to the next element, but until then it remains the same. Can you help me do that?
var numberStrings = ["One", "Two", "Three", "Four", "Five", "Six"];
var i = 0;
setInterval(function() {
document
.getElementById('numberList')
.innerHTML = numberStrings[i++];
if (i == numberStrings.length) i = 0;
}, 2000);
function shuffleUsingRandomSwapping(array) {
var j, x, i = 0,
len = array.length;
for (i; i < len; i++) {
j = Math.floor(Math.random() * len);
x = array[i];
array[i] = array[j];
array[j] = x;
}
}
<button onclick="shuffleUsingRandomSwapping(numberStrings);updateNumberList(numberStrings);">Shuffle Using Random Swapping</button>
<div id="numberList"></div>
updateNumberListfunction