I am currently developing a word game using Vue.
The concept is simple - the player receives a random string of characters and has to input a word that can be formed from those characters. For example, given "ABEOHSTD", the user could enter "BASE" for a score of 4.
One of the challenges I'm facing is verifying the entered words against an external word list stored in a .txt file (which is another issue I need to address separately). Specifically, I'm struggling with confirming whether the words can actually be created using the provided random string of characters.
I'm unsure how to approach ensuring that each letter can only be used as many times as it appears in the original array, or even how to store and calculate the scores. Right now, my main focus is on getting this initial functionality working correctly.
My current approach involves splitting both the entered word and the random string into arrays of individual characters, then looping through them to check if each character in the entered word is included in the random string array.
splitUserCurrentWord = this.userAttemptedWord.split("");
for (var i = 0; i <= splitUserCurrentWord.length; i++) {
if (this.randomStringForGame.split("").includes(splitUserCurrentWord[i])) {
return true;
} else {
return false;
}
}
As it stands, I expect the function to return true only if all the letters in the user inputted word are present in the random string array. However, it seems to only consider the first letter of the array, which is problematic because as long as the first letter matches, it registers as correct regardless of subsequent letters.
You can view the current state of the project on jsfiddle: https://jsfiddle.net/sk4f9d8w/