This code works fine in their example but repeats some of my index items when I try and use it.
var lastloaded = 0;
window.onload = loadPages;
Array.prototype.knuthShuffle = function()
{
var i = this.length, j, temp;
while ( --i )
{
j = Math.floor( Math.random() * (i - 1) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
};
var arr = ["aCard.html", "bCard.html", "cCard.html", "dCard.html"];
function loadPages () {
arr.knuthShuffle();
var frame = document.getElementById("frameWrap");
if (lastloaded+1>arr.length){
lastloaded = window.location = "greatJob.html";
}
frame.src = arr[lastloaded];
lastloaded++;
};
document.getElementById('tom').onclick = loadPages;
Can anyone tell me what I am missing from this code to keep it from repeating items in my array?
arr.lengthtimes ontomthat some pages are loaded multible times? If so that's because you shuffle in theloadPages(At every click ontom)