[Part of the Speaking Javascript project.]
Useful functions and methods from my first two projects — Guess-the-Word & GitHub-Repo-Gallery:
Guess-the-Word
async function – conversion to text with .text method – split string into substrings at space with .split(“\n”)
random selection from an array – makes use of ARRAY[index], Math.floor, Math.random, ARRAY.length, and .trim()
replace letters with symbols – makes use of the for of loop and the .push() and .join(“”) methods – (“”) joins without inserting any spaces
addEventListener(“click”, function(e)) – to use a button to enter info input into a field. Uses .value to capture the input value and to reset the value to an empty string. Checks to see if the guess is valid with an if-clause and the fact that validate(guess) resolves to True if the (exterior) validate function with the parameter guess has a result, and it resolves to False otherwise.
validate input function – confirm that an item entered into a field meets requirements of length and character-type. Uses regex, .length, the NOT operator, and .match [ITEM1.match(ITEM2)]
makeGuess function – check validity and communicate with other functions. Uses .toUpperCase(), if-then, .indexOf(), the NOT operator, the .push() method, and the fact that if ITEM is not an array, .indexOf(ITEM) returns -1 [or .includes() can also be used to confirm whether or not the entered character is already in the array]
showGuessedLetters function – create a list with HTML and populate the list with the items in an array. Uses if-then, DOMObject.innerHTML = “”, document.createElement(“li”), li.innerText=variable, and .append()
updateWordInProgress(guessedLetterArray) – create a string according to a criteria – uses .toUpper, .split(“”), for let, if then, .push
remainingGuessesCounter – checks if an item is in a string with .toUpperCase() if-then ! and .includes – counts according to a criterion with if-then and 1=1
[Part of the Speaking Javascript project.]
Recent Comments