why use count at all when j will give you the same result?
your code should just be this:
code:
var lyricsArray = new Array("Come fly with me, lets fly, lets fly away","Can't buy me love","Yesterday, all my troubles seemed so far away");
var selectedArray = new Array();
function chooseRandomLyric(){
var i = Math.round(Math.random()*(lyricsArray.length-1));
var j;
Inner:
for(j=0;j<selectedArray.length;j++){
if(i==selectedArray[j]){
i=Math.round(Math.random()*lyricsArray.length);
continue Inner;
}
}
if(selectedArray.length === 10){
selectedArray.pop;
}
selectedArray.concat(i,selectedArray);
return i;
}
I did label a function which a lot of people are probably unfamiliar with, but it makes it a little more resource friendly as you can be calling the same function hundreds of times (there is a chance that it will never give you an answer and freeze your computer too.... but this is very limited, but more probable when you have a lot of lyrics and have gone through most of them). And I also added an if statement at the end to make sure that there is no case where there are no lyrics left... which would leave you with an infinite loop too.
Furthermore, dynamic functions are a very wise idea and that is why I have made the random number based upon the array of lyrics rather than you having to do that manually when you update it. I hope you enjoy.
EDIT: updated code due to Volv's post below