I'm trying to make hangman for a Grade 12 Assessment piece.
I need to create variables due to the length of the current word chosen to be guessed. For example, if the word is 'cat', then
letter0 = 'c'
letter1 = 'a'
letter2 = 't'
So far, I have gotten some progress with a for loop.
for (i = 0; i <= currentWord.length){
//var letter(i) = currentWord.charAt(i)
i++
}
The commented out line was what I was aiming for, where the letter position would be put into the variable. Obviously this doesn't work, as the variable is just straight up read as letter(i)
instead of letter(possible number)
. The loop would then stop once the length had been reached, and therefore there would be a unique variable for each letter of currentWord
.
Any ideas of how to make this work?
Thanks!