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 trialAlex Lang
1,110 PointsWhy won't this work?
var upper = 10000;
var randomNumber = getRandomNumber(upper);
var guess;
var attempts = 0;
function getRandomNumber (upper) {
return Math.floor(Math.random() * upper ) + 1;
}
while (guess !== randomNumber ) {
guess = getRandomNumber( upper );
attempts += 1;
}
document.write("<p>The random number was " + randomNumber + "</p>");
document.write("<p>It took the computer " + attempts + "attempts to get it right.</p>");
Alex Lang
1,110 PointsWhen I preview it, nothing pops up.
5 Answers
KRIS NIKOLAISEN
54,971 PointsThe source for your script is app.js. But the code is in while.js. Make the following change in index.html
<script src="while.js"></script>
Mimi Hoang
960 PointsI'm having the same problem and i added the script anyone know what's wrong?
Steven Parker
231,268 PointsIf the answer here didn't resolve your issue you may have a different cause. Start a fresh question where you can share your own code and we can take a look. Remember to use Markdown formatting.
Lynn Collins
10,080 PointsI tried EVERYTHING....still does not WORK! So frustrated!
Steven Parker
231,268 PointsStart a fresh question where you can show your own code, I'll bet someone can help!
Steven Parker
231,268 PointsThis code does work, but remember when dealing with random numbers, the specific results you get will vary from those in the video. In fact, if you try it more than once, you will notice that the number of attempts will be different each time.
Steven Parker
231,268 PointsLooks like Kris beat me to it, but you can see that snapshot made the answer possible.
Steven Parker
231,268 PointsWould the person who downvoted this answer please leave a comment and let me know what I could do to improve it? Thanks!
Alex Lang
1,110 PointsWhen I preview it, nothing pops up.
Steven Parker
231,268 PointsAre you using the workspaces? If so, you could make a snapshot of your workspace and post the link to it here. Then we could replicate your issue.
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsIt seems like it works to me. What does it not do?