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 trialJustin Glover
1,685 PointsWhy doesn't this code produce anything?
function randomNumber(upper) { return Math.floor( Math.random() * upper ) + 1; } var counter = 0;
while(counter <= 10){ document.write(randomNumber(5)); counter += 1; }
Matthew Long
28,407 PointsIs your script.js
file linked to your index.html
using the <script>
tag?
Matthew Long
28,407 PointsYou don't have to create a variable and then return it. Like in your example, you can return it right off the bat. Generally you only need to create a variable if you're going to do something with it before you return it. Dave is probably just trying not to throw too much at the viewer at once.
Justin Glover
1,685 PointsOh okay, thank you !
Matthew Long
28,407 PointsNo problem!
Justin Glover
1,685 PointsJustin Glover
1,685 PointsNevermind, i got ahead of myself and there was no <script> tag in the HTML file. But now my new question is, why did Dave in his example create a variable randNum? In my example i was able to do so without that variable?