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

Kristenia Clark
Kristenia Clark
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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
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.

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 :)