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?

Ira Jerry
Ira Jerry
3,292 Points

My loop code isn't working, I followed along with Dave Please help.

-------------Javascript------------------

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

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

3 Answers

Hi! It looks like you need a closing " after scripts.js in your html file.

Hey Ira,

Your loop code is working exactly as it should. There are no errors of any kind in your code. First, make sure when you're running the scripts in a page that the scripts are contained within a <script> element, and that your HTML is set up properly.

Also, make sure your page is saved before refreshing the page and previewing the changes. If that does not work, you should delete your recent history. Your browser may be attempting to use a cached version of your script.

If none of that works, please post your full code like how its shown below. You would replace "css" with "javascript" when doing a code block:

code

Ira Jerry
Ira Jerry
3,292 Points

Thanks guys it worked.