Question
JavaScript This is the HTML file I'm working with: P5 Word Guess Word: Guess > Start > Letters Guessed At the top of my p5.js
JavaScript
This is the HTML file I'm working with:
Word Guess
Word:
>>
Letters Guessed
At the top of my p5.js I have these variables initialized:
const words = wordsList; //refers to words array from p5-words.js
const guesses = []; //initailized to empty array
const word = ""; //initialized to empty string
function handleStartRestartButtonClick() { var elem = document.getElementById("startButton"); //Get element in var "elem" elem.innerHTML = 'Restart'; //Change inner text to "Restart" var str2 = "_"; //new string = "_" word = str2; //make word = _ guesses.splice(0, guesses.length); //Empty the "guesses" array. }
This is question I need answered:
H. displayWordUnderscores() function
This function will update the word span with either underscores for unguessed word letters, or the guess letter. Underscores or letters must be separated by a space.
Additional notes:
Make a new array that has the same amount of underscores as the word has letters- this is what you are gonna want to display. Then use a for loop to cross-check the contents of your guesses array with your word and if they match, then replace the index value or your new array with the same index value of where that letter is in your word.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started