Checking if the user’s entered word is possible
Looking for duplicate words is not enough. Now that we have generated a random seven-letter word, we want to make sure that the user’s entered word can be made from the letters that are in the random word. For example, if the random word is bookend and the user types in books
, that would be invalid because s
is not in the random word.
Let’s go back to the DataModel
class and add code to the isWordFoundInBaseWord
function so that we can check that the word can be made from baseWord
:
//check to see if the word is possible given the baseWord letters func isWordFoundInBaseWord(userGuessWord: String) -> Bool { var comparisonWord = baseWord return userGuessWord.allSatisfy { letter in ...