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 Create a while Loop

Brooke Guy
Brooke Guy
8,179 Points

I am getting a Syntax Error: Parse Error here and can't figure out why..help?

I am getting a Syntax Error: Parse Error here and can't figure out why..help?

I literally did it exactly the way he did it in the video and cannot figure out what i did wrong...

script.js
function randomNumber (upper) {
  return Math.floor ( Math.random()* upper ) + 1;

var counter = 0;
while (counter <= 26) {
  var randNum randomNumber(6);
  document.write(randNum + ' ');
  counter += 1;
}

1 Answer

Herleen D
Herleen D
4,444 Points

Your while loop and your function are within the same code block, so that's why you couldn't call it inside your loop. I added a curly braces to signify the end of the function, and you also forgot to assign var randNum to randomNum(6) so I also added an equals sign.

function randomNumber (upper) {
  return Math.floor ( Math.random()* upper ) + 1;
}

var counter = 0;
while (counter <= 26) {
  var randNum = randomNumber(6);
  document.write(randNum + ' ');
  counter += 1;
}