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?

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.