Workshop › Hangman › Step 28 of 36
A random pick can give the same word twice in a row, and players find that broken. A do ... while loop picks again
until the new word differs from the last one.
```js
function newWord() {
let next
do next = WORDS[Math.floor(Math.random() * WORDS.length)]
while (next === word) // never the same word twice in a row
word = next
guessed = new Set()
```next is the candidate word.do ... while (next === word) picks a candidate, then repeats as long as it equals the current word.word become next.In newWord, replace the word = WORDS[...] line with the four lines. Press Run.
Skills: Loops
← Play again A winning streak →