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 trialMichael Fazekas
3,070 Pointsrandom 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; }
3 Answers
Steven Parker
231,269 PointsCongratulations on resolving your issue.
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
5,500 PointsI 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
231,269 PointsIn 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
5,500 Pointsthank you, this is helpful, will definitely start a new question with a screenshot link
Steven Parker
231,269 PointsJust 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.
Michael Fazekas
3,070 PointsMichael Fazekas
3,070 Pointssorry guys I figured it out I had var = randNum = randomNumber.. I took out the var = and put var randNum =.