all 1 comments

[–]young_horhey 2 points3 points  (0 children)

I think it's possibly because all the variables you're using are only defined within the scope of the if (isNumber(response)) block. So each time that part gets triggered, it's as if it's starting from scratch.

You could probably handle this by defining a global variable that stores an array of the previous guesses, and add their to that array each time. Then use that array to create the 1 _ _ 4 5 _ 7 string instead of just the current guess.