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 trialSusan Rusie
10,671 PointsNot sure why my code isn't showing the random numbers
I just finished watching this video and have gone over and over this code. I don't know why my code is only showing the title but no random numbers. I have even tried refreshing the browser to see if that made a difference, but it hasn't. What is missing that would fix this problem.
2 Answers
Steven Parker
231,275 PointsYou forgot to blockquote your code, so some of it is not visible. To quote your code, skip a line, put a line with only three accents ("backticks") and the language id, then the code, then another line with just 3 accents, like this:
```js
(code goes here)
```
But I took a guess that your code was originally like this:
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;
}
This code ran fine and produced 10 random numbers between 1 and 6. But no title - and I don't see anything in the code that would create a title.
Susan Rusie
10,671 PointsSorry about that. I still can't get it to show the random numbers, just " Let's Make Random Numbers". Here is my code:
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,275 PointsThe while condition is incomplete, and the open brace for the block is missing (same problems as the unquoted version).
If you look at my version, you'll see where I guessed it was intended to test for 10 iterations. With those fixes applied, it worked fine.
while (counter < 10) {
What is displaying "Let's Make Random Numbers"? Certainly nothing in this code. Is there an HTML part that goes with this? Is this from a workspace that you could snapshot and share a link to?
Susan Rusie
10,671 PointsI wasn't sure how to post the HTML, but it's fixed now. Thanks again for your help.
A X
12,842 PointsSusan, just to mention, this isn't HTML, this is the programming language JavaScript. I know it can get confusing considering all three languages: HTML, CSS, and JavaScript all work together to create a web page. If it would help to have a relational, if you know anything about Japanese, you can't just translate Japanese into English. You have to use three different forms of Japanese: hiragana, katakana, and kanji to translate. They're not the same as each other, but they're all needed to create the whole process of translating from one language to the other. This is the same for JavaScript: it's part of a three step process of languages to make a web page.
Susan Rusie
10,671 PointsSusan Rusie
10,671 PointsHere is my code:
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; }
<!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>