Vue
HTML
<main id="app">
<input type="number" id="entryValue">
<p>This is your random string "OHJTAYUCFN"</p>
<input type="text" v-model="userAttemptedWord" style="text-transform: uppercase" placeholder="Enter a word">
<button class="submitWord">Submit this word</button>
</main>
Vue
new Vue({
el: "#app",
data: {
stringLength: 0,
randomStringForGame: 'OHJTAYUCFN',
userAttemptedWord: '',
wordExistsInWordList: '',
wordContainsValidCharacters: '',
wordAccepted: '',
wordList: ['JOY', 'FUN', 'HOT', 'NOT']
},
methods: {
submitWord:
function () {
if (checkWordExistsInList() && checkWordHasValidCharacters()) {
this.wordAccepted = true;
}
else {
this.wordAccepted = false;
};
}
},
computed: {
splitUserAttemptedWord: function () {
return this.userAttemptedWord.split("");
},
checkWordExistsInList: function () {
word = this.userAttemptedWord;
return this.wordListArray.includes(word);
},
checkWordHasValidCharacters: function () {
splitUserCurrentWord = this.userAttemptedWord.split("");
for (var i = 0; i <= splitUserCurrentWord.length; i++) {
if (this.randomStringForGame.split("").includes(splitUserCurrentWord[i])) {
return true;
}
else {
return false;
}
}
}
}
});