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 trialMark Shiel
12,225 PointsIsn't it better to check the user input in the while loop rather than creating an infinite loop and breaking out of it ?
In my final code I used while (userInput!=="quit") { /* code to search and prompt user */}
Is this not more appropriate or did I miss something?
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsIt's just another way of doing it. You would probably want to account for the case where the user presses Esc
on their keyboard or presses the 'Cancel' button in the prompt window. In that case, the value of userInput
would be null
and still not equal to "quit"
.
If you made use of an and (&&
) in your conditional for the while
loop, that might do it.
Also, because you want to show the prompt at least once, perhaps a do... while
loop would be more appropriate?