Workshop › Hangman › Step 5 of 36
Each game needs one secret word. newWord picks a random item of WORDS and keeps it in word.
```js
let word
function newWord() {
word = WORDS[Math.floor(Math.random() * WORDS.length)]
}
newWord()
draw()
```let word makes a variable whose value can change. It is empty (undefined) until newWord fills it.WORDS.length is the number of words (50). WORDS[0] is the first word, WORDS[49] the last.Math.random() gives a random number from 0 up to (not including) 1. Times 50, it is from 0 up to 50.Math.floor rounds down, so the index is a whole number from 0 to 49.newWord() is called once at the start, before draw().], leave an empty line and write let word and the newWord function.newWord() above draw(). Press Run.Skills: Arrays and objects, Functions
← A function that draws Write the word →