+ 1

code won't return value for some reason

I am making Hangman. I tested it a specific code but it didn't work. So I debugged it. I don't know why it always returns 'undefined'. This is the code ---- function confirm() { var inp = $('textarea').val() var c = null var x = 0 for(; x <= word.length; x++) { if (!c) { c = (inp == word[x]) } } if (c === true) { display[x] == word[x] // piece of code that returns 'undefined' alert(display[x]) writeOnScreen() document.getElementById('right').play() } else { attempts-=1 $('.ats').text(attempts) document.getElementById('wrong').play() drawVisual() } } ----- FYI there is a variable named 'display'. It's value is '??????'. I defined it like this l var display = '??????' l. So now you won't say it returns undefined because there is no variable display. If you know why, please reply why it keeps returning null. If you know how, you can fix the code.

28th Mar 2017, 5:29 PM
koder
koder  - avatar
2 Respostas
+ 1
OH WAIT (checks code) (rewrites)
28th Mar 2017, 5:32 PM
koder
koder  - avatar
+ 1
I fixed the piece of code returning 'undefined' but now it doesn't set the letter of the display.
28th Mar 2017, 5:36 PM
koder
koder  - avatar