What I did was first I changed the condition for the while. Instead of just userGuess !== chosenNumber I added && userGuessCount < 3 so that the loop also stopped when the user guessed too many times. Then I was able to take the second if/else that was INSIDE the while OUTSIDE cause it only needed to happen when the game was over. This way I was also able to remove the breaks since the while loop conditions alone were enough to know when the loop was done.
But this ^ does not solve the problem you mentioned about saying higher or lower after your third guess. But I did also rewrite a bit of this and commented it up nicely for ya! Let me know if you have any other questions !
Corey!!! I love what you did and wow you made it preform so much better!!! Thank you for all the comments in the code, I will be studying this to make sure I can apply this into my future projects.
I like the fact you don't have to reset the browser or use any breaks! That makes it so much cleaner and easier to understand.
I'm glad you liked it and you found it easy to understand! You had a great start I just tweaked it a bit! You even knew what functions to call for the random number generation!
Ya breaks definitely have their place but I think it can be easier to reason about without them sometimes.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So here is a pen that is the closest to what you started with: codepen.io/anon/pen/PvXXqO
What I did was first I changed the condition for the while. Instead of just
userGuess !== chosenNumber
I added&& userGuessCount < 3
so that the loop also stopped when the user guessed too many times. Then I was able to take the secondif/else
that was INSIDE the while OUTSIDE cause it only needed to happen when the game was over. This way I was also able to remove thebreak
s since the while loop conditions alone were enough to know when the loop was done.But this ^ does not solve the problem you mentioned about saying higher or lower after your third guess. But I did also rewrite a bit of this and commented it up nicely for ya! Let me know if you have any other questions !
Corey!!! I love what you did and wow you made it preform so much better!!! Thank you for all the comments in the code, I will be studying this to make sure I can apply this into my future projects.
I like the fact you don't have to reset the browser or use any breaks! That makes it so much cleaner and easier to understand.
Thank you very much!
I'm glad you liked it and you found it easy to understand! You had a great start I just tweaked it a bit! You even knew what functions to call for the random number generation!
Ya
break
s definitely have their place but I think it can be easier to reason about without them sometimes.