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 trialLuca Di Pinto
8,051 PointsIs it possible?
Hi guys, I don't understand the logic of the "do.. while loop". I mean.. Could it be possible to use this code?
'''javascript do { guess = prompt('I am thinking of a number between 1 and 10. What is it?'); guessCount +=1; } while ( ! parseInt(guess)===randomNumber) '''
Thanks for the answers! Luca
1 Answer
lambda
12,556 PointsHere's some videos on loops https://teamtreehouse.com/library/feeling-loopy-with-java (The code is java but the syntax is very similar, and it explains the ideas very well).
// this is how do-while loops work.
do {
// statement 1 will run at least 1 time (can be more if condition is true)
// statement 2 will run at least 1 time (can be more if condition is true)
} while( condition ); // keep doing statements 1 & 2 when the while condition is true. stop when condition is false
Could it be possible to use this code?
Yes, you can use that code. But you need to declare and initialize "guessCount" and "randomNumber"