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 trialJaclyn Mamuzich
2,298 PointsNot sure what's wrong with my code but I can't seem to get my js to work. All I see is the header from index.html
var upper = 1000;
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("The random number was " + randomNumber);
document.write("It took the computer " + attempts + " tries to get it right");
Jaclyn Mamuzich
2,298 PointsHi Marcus, here is a link to my workspace snapshot: https://w.trhou.se/v95kgtcqy0
thanks
3 Answers
Marcus Parsons
15,719 PointsJaclyn,
There's nothing wrong with your code or workspace at all. Everything is referenced correctly, and the random number generator is working as expected. Did you make sure you saved all pages you were working on and then refresh the page? If refreshing doesn't work for you, try clearing your internet history in the browser including cache. The browser can sometimes be trying to use a cached version of the site.
Allison Davis
12,698 PointsHi Jaclyn, I just tried your code and it worked on my end - maybe save everything in workspaces and try again?
Jaclyn Mamuzich
2,298 PointsThank you both for your reply. I tried that and it worked!
Marcus Parsons
15,719 PointsAwesome blossom! If you want to go ahead and select a best answer, we can mark this as resolved! ^_^
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsHey Jaclyn,
If you're working on this in Workspaces, can we see a snapshot of your workspace? I have a feeling that the js isn't linked correctly somehow. If you don't know how to do that, here's a handy forum post for ya: http://www.teamtreehouse.com/forum/workspace-snapshots