Hi everyone,
I've been struggling on a hangman game the past few hours and I got almost everything down except the multiple letters part.
Like if the word is "camera" but whenever the user inputs "a" it only shows "-a----" instead of "-a---a"
this is my code so far:
if (secretWord.indexOf(letterGuess) >= 0) {
updatedWord = wordSoFar.substring(0,
secretWord.indexOf(letterGuess));
updatedWord += letterGuess;
updatedWord += wordSoFar.substring(
secretWord.indexOf(letterGuess) + 1,
wordSoFar.length());
wordSoFar = updatedWord;
}
and i know indexOf() only returns the first occuring letter, so I'm wondering how to return EVERY occuring letter.
and is there a way to do this other than char and arrays cause I was googling online and it's always done with char and array but I haven't learned that yet.
Any help is appreciated!