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?

Kyle Gibbons
Kyle Gibbons
1,388 Points

Hello, I'm confused on why my code is not printing out random numbers ?

function randomNumber(upper) {
  return Math.floor( Math.random() * upper ) + 1;
}
    var counter 0;
    while ( counter < 1000) {
      var randNum = randomNumber(7);
      console.log(randNum + ' ');
      counter += 1;
}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Short answer? You're missing an equals sign :smiley:

Change this:

var counter 0;

To this:

var counter = 0;

You will soon be flooded with 1000 random numbers just like I was :wink:

Oh the littlest things! They really do make all the difference!

Kyle Gibbons
Kyle Gibbons
1,388 Points

Thank you, yes a very little thing. I went up and down it 10 times and couldn't find what was wrong there, I appreciate the help.

Matthias Nörr
Matthias Nörr
8,614 Points

What does the "7" inside the randomNumber function mean again?

var randNum = randomNumber(7);
nico dev
nico dev
20,364 Points

It's an argument that will give you a random number from 1 up until 7.

About passing arguments to functions, this is the best explanation I've ever seen. Feel free to check back again that video, and if you still have doubts, get back. :)