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 What are Loops?

random numbers not showing up on preview mode?

My random Number is not showing up on preview mode I followed everything and double checked everything seems good?

html:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Let’s Make Random Numbers</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Let’s Make Random Numbers</h1> <script src="scripts.js"></script> </body> </html>

JavaScript: function randomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; } var counter = 0; while (counter < 10 ) { var = randNum = randomNumber(6); document.write(randomNumber + ' '); counter += 1; }

sorry guys I figured it out I had var = randNum = randomNumber.. I took out the var = and put var randNum =.

3 Answers

Steven Parker
Steven Parker
210,424 Points

Congratulations on resolving your issue. :+1:

But for future questions, be sure to use "Markdown" formatting. There's a pop-up "cheatsheet" below, or you can watch this video on code formatting.

M Angele U. GASANA
M Angele U. GASANA
5,500 Points

I have the same issue, can't get one single random number and I can't figure out where I did wrong! P.s: my script file is already linked to html ! function randomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; } var counter= 0; while ( counter < 10){ var randNum = randomNumber(6); document.write(randNum + ''); counter+=1; }

Steven Parker
Steven Parker
210,424 Points

In future, instead of asking a question in an "answer" to another question, always start a fresh question.

But this code seems OK, and should generate 10 random digits. If you're still having trouble, start a new question where you can make a snapshot of your workspace and post the link to it.

And BTW, it's not necessary to concatenate that empty string. The "write" function will work with a number argument.

M Angele U. GASANA
M Angele U. GASANA
5,500 Points

thank you, this is helpful, will definitely start a new question with a screenshot link

Steven Parker
Steven Parker
210,424 Points

Just to be clear, I was suggesting a snapshot not a "screenshot". Click on the colored link word in the last comment for instructions on how to make them.