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;
}