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 trialGreg Clinton
8,091 PointsMy refactor answer
here is what i came up with. It's works, any comments?
var i = 0;
var html = '';
var red;
var green;
var blue;
var rgbColor;
for ( var i = 1; 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);
Rich Donnellan
Treehouse Moderator 27,708 PointsSean T. Unwin – the forum needs a sticky for this exact reason (code posting) and many others!
Greg Clinton
8,091 PointsA sticky would be nice about the code format, I have read it and will do it next time.
This is my answer for the refactor challenge on the loops javascript course. I though each course had a section but I guess not if it's in general javascript. Thanks anyways!
Sean T. Unwin
28,690 PointsThere is also the 'Markdown Cheatsheet' popup link that is in between the text area and buttons in order to assist when you write a comment or post.
Jonathan Cousins
4,160 PointsYou've duplicated Math.floor(Math.random() * 256 );
. Why not put it in a variable? This would increase the performance of the script.
Sean T. Unwin
28,690 PointsSean T. Unwin
28,690 PointsI have formatted your post to display the code properly. Read how to post code to the forum if you need help in the future.
Would you mind letting us know what this is a refactor of?
It works nicely by the way. :)