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 trialAkeia Escobar
1,957 PointsI got my code to work, but how is it's readability?
var html = ''; var color; var rgbColor;
var colorCounter = 0; var color = function getColors(upper) { return Math.floor(Math.random() * upper); }
do { rgbColor = 'rgb(' + color(256) + ',' + color(256) + ',' + color(256) + ')'; html += '<div style="background-color:' + rgbColor + '"></div>'; colorCounter += 1; } while ( colorCounter <=10 );
document.write(html);
Anything I should change? Thanks!
1 Answer
Steven Parker
231,268 PointsYou could give your function the name you will call it by and skip the assignment:
function color(upper) { return Math.floor(Math.random() * upper); }
OR you could assign it using the compact "arrow" function syntax:
var color = upper => Math.floor(Math.random() * upper);
And when posting code, use Markdown formatting (as I did here) to preserve the code appearance.