Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops A Closer Look at Loop Conditions

Jaclyn Mamuzich
Jaclyn Mamuzich
2,298 Points

Not 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");

Hey 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

Jaclyn Mamuzich
Jaclyn Mamuzich
2,298 Points

Hi Marcus, here is a link to my workspace snapshot: https://w.trhou.se/v95kgtcqy0

thanks

3 Answers

Jaclyn,

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
Allison Davis
12,698 Points

Hi Jaclyn, I just tried your code and it worked on my end - maybe save everything in workspaces and try again?

Jaclyn Mamuzich
Jaclyn Mamuzich
2,298 Points

Thank you both for your reply. I tried that and it worked!

Awesome blossom! If you want to go ahead and select a best answer, we can mark this as resolved! ^_^