Loading...
beginner
Problem 03 • Step 04
Wire It Into the Game
You have randomWord and createGameState. Now compose them.
startGame(wordList, random) picks a random word from the list and returns a fresh game state for that word. Look at game.html to see how it fits: startGame(words, Math.random) replaces the old hardcoded createGameState("apple").
Because startGame accepts the random function, your tests stay deterministic. Pass in a function that always returns 0 and you know exactly which word you will get.
Examples
function zero() { return 0; }
startGame(words, zero)
// { word: "apple", guessedLetters: [], guessesRemaining: 6 }
function almostOne() { return 0.99; }
startGame(words, almostOne)
// { word: "kiwi", guessedLetters: [], guessesRemaining: 6 }