I am creating a hangman game and I am selecting a random word from a pre-defined array.
Like so:
// Select random word to guess
function getWord() {
var a = new Array('one', 'two', 'three', 'four');
return a[parseInt(Math.random() * a.length)];
}
Is what I would like to do is to stop it choosing the same word twice or more. Currently, when using a small array of words, it sometimes repeats the same word 2 or 3 times in a row.
I am not quite sure how to go about combatting this.
First I thought maybe inserting the word into a new variable and then comparing but not sure that is a great way to do.
Any ideas wuld be helpful. Thanks!