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 The Refactor Challenge

Workspace preview causes chrome to hang

Again, an issue where my code matches the solution code yet my result is different. In this case I have refactored the code to the below. which matches exactly to the solution code.

BUT when I click the eyeball to preview the code in the browser window, it causes all my treehouse tabs to hang. it doesn't look like I've created an infinite loop anywhere, but at this point, I'm not sure I'm doing anything right.

Any help is appreciated. Thanks!

var html = '';
var red;
var green;
var blue;
var rgbColor;

for (var i = 0; i < 10; i =+ 1) {
  red = Math.floor(Math.random() * 256 );
  green = Math.floor(Math.random() * 256 );
  blue = Math.floor(Math.random() * 256 );
  rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')';
  html += '<div style="background-color:' + rgbColor + '"></div>';
}
document.write(html);

lastly, I've run the downloaded solution code and it behaves the exact same way it's demo'd in the video.

Thanks!

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

Just a quick glance, it looks like you have the incrementing symbol backward for the variable in the for loop. You have =+ when it should be +=.
Give that a go and see if that solves it.

:) :dizzy:

P.S. I also added JavaScript declaration to the Markdown for the code so syntax highlighting is correct. :)

well....that's not at all embarassing.? Thank you for finding what I couldn't after having stared at it for an hour.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

You're welcome. :smiley: Don't worry... I've been there too. Lol.