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 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
231,275 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
231,275 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
231,275 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.