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
Brad Horvath
3,845 PointsNeed help using loops
Can somebody tell me what is wrong with this code? It doesn't seem to be running.
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper ) + 1;
}
var counter = 0;
while ( counter < 10 ) {
var randNum = getRandomNumber(6);
document.write(randNum + " ");
counter += 1;
}
```
1 Answer
Saskia Lund
5,673 PointsYour code is perfectly fine and should run.
Most probably you forgot to tell your index.html to use the JavaScript file.
Did you place the following code right above your closing body tag?
<script type="text/javascript" src="script.js"></script>
</body>
content of script.js:
function getRandomNumber(upper) {
return Math.floor( Math.random() * upper ) + 1; }
var counter = 0;
while ( counter < 10 ) {
var randNum = getRandomNumber(6);
document.write(randNum + " ");
counter += 1;
}
Like this?
Brad Horvath
3,845 PointsBrad Horvath
3,845 PointsYep. You were right. Thanks for the help