+ 2
Please help me with this code
Hello, In this code the correct guesses are not replacing the correct index of the dashes. What should I do?😐 Thanks in advance 😃 https://code.sololearn.com/W2IisRvg7jzc/?ref=app
9 Answers
+ 1
I have realised you don’t even need to trim for whitespaces, your ‘blankSpaces’ variable from the start begins with the culprit whitespace
Initialise var blankSpaces to “” instead of “ “ and that should do the trick 👍🏾
+ 4
Let us know where error is comming and how you want it to work.
//this is your code and you only know what is going on on it.😊
+ 1
Its a standard hangman game. The guessed letters should replace their respective dashes as the user enters input.
+ 1
(This isnt my answer but adding for more context)
Do alerts in the oninp() method: say your chosen word is ‘javascript’ and you guess ‘a’
the output is
a _ a _ (rest of dashes without the _ firsr for the j)
when you guess the first letter correctly, it adjusts itself
+ 1
Hey thanks😁. But I already suspected that the blank spaces variable was the problem but didn't even think it's initializer was the culprit 😀😁😁
0
Jenine, that's the problem. I want the first dash to be replaced.
This code prints the 'j' where there is no dash and if you find the whole word, it looks like: 'javascript_ '
0
Evans , yes I added that to try and explain the problem with an example. My approach to debugging is a lot of console.log statements.
If you alert/console.log ‘dash’ on line 43 when you getElementById, there is a whitespace before the dashes so ‘ —-‘ alert(“dash is ‘“+dash+”’”)
See if you need to trim this when obtaining the value?
0
But how do you do that? Please help me. I don't understand that part😑
0
No problem 😊