JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Create a while Loop

Kristenia Clark
Kristenia Clark
Full Stack JavaScript Techdegree Student 2,252 Points

I'm getting Syntax error over and over again. What did I miss?

I have Syntax Error but I'm unable to see where I'm doing wrong

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

2 Answers

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

You have no variable named counter, only count. You need to change where it says counter to count and remove the var keyword from the while loop code block.

Fabion Delishaj
Fabion Delishaj
12,878 Points

Hi Clark,

Because you are using different variables, you just need to use one variable "count".

var count = 0;
while ( counter < 26 ) { /* The variable counter doesn't exist, so the while loop doesn't know if the value is less than 26 */
  var count = randomNumber(6); /* You don't need this */
  document.write ( randNum + ' ' ); /* Same here, randNum doesn't exist */ 
  counter + = 1; /* Pay attention here, there is space between + and = */
} 

The challenge is asking to print the variable until it reaches 26 through a while loop.

var count = 0; /* Set value 0 */

while ( count < 26 ) { /* Set the condition for the loop "Count until count is 26" */

     document.write (count); /* Print the value of count */
     count += 1; /* Increment of 1 the value */
     /* When the value reach 26 the loop will stop */
} 

I hope this will help you :)