I'm looking to make a list item randomizer that only displays that item once. I have a basic randomizer working that pulls from an array, but when I click the button, it just continues to loop through each item. Is there a way to get each item it only display once then stop and/or display something like "list over" once complete? My js skills are very basic...
The js randomizer code:
var techniques = [
"item 1",
"item 2",
"item 3",
"item 4",
"item 5"
]
function newTechnique() {
var randomNumber = Math.floor(Math.random() * (techniques.length));
document.getElementById('techDisplay').innerHTML = techniques[randomNumber];
}
and the html
<div id="techDisplay"></div>
<button onclick="newTechnique()">New Technique</button>
I'm also wondering if there is a better way to pull in data, like using an xml or something? I intend to have likely over 50 items in the list, which could become cumbersome in the js. Let me know and thanks in advance!
Aucun commentaire:
Enregistrer un commentaire