Im making a fun randomizer for a little bit of practice im, stuck on the if statment were if there is an double randomize that index. i got it working for the first and last index by comparing the middle index however I now want to compare the two ends to each. after that I have to see if the random number is the same in every index I plan on using the dom later on but for now im console.loging to see the results in the deloper tools thanks for your help.
var abcs = ["a", "b", "c"];
/*takes the length of an array and gives each index
a random whole number and stores the random numbers
in an empty array*/
function shuffle(array, randomIndex){
/*the randomIndex values are stored in this empty
array*/
var arrayIndex = [];
//makes a random whole number between 0 and 9
function randomIndex(){
return Math.floor(Math.random() * 10);
}
/*loops through an array and stores its value in an
empty array*/
for(var i = 0; i < array.length; i++){
arrayIndex.push(randomIndex(array));
//checks to see if there are doubles
if(arrayIndex === arrayIndex[i - 1]){
console.log("double");
}
}
console.log(arrayIndex);
}
var abcs = ["a", "b", "c"];
/*takes the length of an array and gives each index
a random whole number and stores the random numbers
in an empty array*/
function shuffle(array, randomIndex){
/*the randomIndex values are stored in this empty
array*/
var arrayIndex = [];
//makes a random whole number between 0 and 9
function randomIndex(){
return Math.floor(Math.random() * 10);
}
/*loops through an array and stores its value in an
empty array*/
for(var i = 0; i < array.length; i++){
arrayIndex.push(randomIndex(array));
//checks to see if there are doubles
if(arrayIndex === arrayIndex[i - 1]){
console.log("double");
}
}
console.log(arrayIndex);
}