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?

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,360 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. :)