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

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