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 trialRahul Reddy Hanumanthgari
1,174 PointsI have a questions this look is going infinite until your guess number is equal to the random number?
var guess; var guesscount = 0; var correctguess = false; var rn = randomNumber(10);
function randomNumber(upper){
var randomNum = Math.floor(Math.random() * upper) +1;
return randomNum;
}
do{
guess = prompt("Guess between 1 to 10");
guesscount +=1;
if(parseInt(guess) === rn){
correctguess = true;
}
}while(!correctguess);
document.write("congrats you guessed" + guesscount + " with correct guess" + rn );
1 Answer
Steven Parker
231,269 PointsYes, this program will never end until you guess the correct number.
Luckily, there's only 10 possible choices.