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 trial

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

Devon Deason
Devon Deason
7,061 Points

No results display in preview?

I'm sure its something small, but nothing displays other than "let's Make Random Numbers" when I preview in workspaces. Even the JavaScript console is blank. I've done no editing to the index.html file.

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 = randomNumber( upper );
  attempts += 1;
}
document.write("<p>The computer took " + attempts +  " to guess the number " + randomNumber ".</p>");

3 Answers

Not sure if this is it, but there's a missing + between randomNumber and closing p tag. Should be:

document.write("<p>The computer took " + attempts + " to guess the number " + randomNumber + ".</p>");

Change randomNumber to getRandomNumber, the function you created.

Daniel Rowlands
Daniel Rowlands
Courses Plus Student 4,438 Points

I believe he is not talking about the function. Looks like he just required the randomNumber function. If he called the getRandomNumber function, he would get a new value printed out.

im also having same situation .. couldn't find any error..