Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTeacher Russell
16,873 Pointsdo...while
Oh my, I was just being nostalgic and revisiting these exercises of long ago. This code runs here, but never end. No match. Originally I had done this from memory in my text editor using es6 syntax and had problems. For one, it said prompt was undefined. I came back here to test it on Treehouse, and something's still not right.
1 Answer
Steven Parker
231,268 PointsHi, I got your request message.
The "prompt" method should be a built-in available in any browser. Did you try running in a server-side JavaScript engine like Node.js?
But the issue with the code is due to the handling of the guess:
guess = prompt('I am thinking of a number between 1 and 10. What is it?');
guess += 1;
So if the input is a string of digits between 1 and 10, the next line tacks on another "1" digit making it 11, 21, 31, ...etc up to 101. Since none of these will ever match a random number between 1 and 10, the loop never ends.