I’ve been playing with random array arrangements and was wondering if there is a way to pull word from the array only once. So every time you click on the changeWorld button then it will randomly draw from the array list until all the words where used only once?
Learning JavaScript so I don't need anyone to write me the code, just want get pushed in the right direction and know if it is possable. There isn't anything I can find that address the concept.
<body>
<button id="change-world-btn">Change World</button>
Hello <span class="world-name">World!</span><br />
<script type="text/javascript">
var worlds = new Array ("Pluto", "Mars", "Saturn", "Jupiter", "Uranus");
function newWorld() {
return worlds[Math.floor(Math.random() * worlds.length)];
}
elements = document.getElementsByTagName('span');
document.getElementById('change-world-btn').onclick = function() {
world = newWorld();
for(var i = 0, el; el = elements[i++];) {
if(el.className == 'world-name') {
el.innerHTML = world;
}
}
};
</script>
</body>