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?

My code won't run

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;
}

11 Answers

melissakeith your script call in the index.html is wrong

you have the following in you code <script src="js/random.js"></script>

You need to change it to; <script src="random.js"></script>

Did you make sure and put the script tags in your html?

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

Yes, this is what I have and it doesn't run, neither does the random number challenge part two. https://w.trhou.se/mo7pz7kfng

Its happening the same with me.

When I preview it, it doesn't run. It just says "Let's make random numbers", I've already tried restarting workspace and as far as I can see its exactly like the code in the video.

same with me

Seems to be a problem with Workspace, it just happens randomly, that the code looks fine and it still doesn't work.

Same here!

It's happening with me, as well, but I'm using Atom as for my workspace.

I had my condition opposite to what should be. I had the greater than symbol versus the less than symbol. This is what was breaking my code.

Wrong: while (counter > 10 ) {

code

}

Right: while (counter < 10 ) {

code

}

Taqwa R
Taqwa R
1,852 Points

Same thing is happening with me as well. I'm guessing it's a bug.

Same is happening with me https://w.trhou.se/azdl68wj7l