re: Review my JavaScript? #2 VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Please share what you have in mind! I would love to see how you would do it. Thank you for offering to do so! I think the thing that bugs me is t...
 

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 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.

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 breaks definitely have their place but I think it can be easier to reason about without them sometimes.

code of conduct - report abuse