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 trialsuthin
5,997 PointsWondering if this solution also makes sense?
let html = '';
let red;
let green;
let blue;
let randomRGB;
const randomValue = () => Math.floor (Math.random() * 256);
const randomRGB = rgb( ${randomValue()}, ${randomValue()}, ${randomValue()} )
;
for (let i = 0, i < 10, i++){
red = randomValue ();
green = randomValue();
blue = randomValue();
randomRGB;
html += <div style="background-color: ${randomRGB}">${i}</div>
;
}
document.querySelector('main').innerHTML = html;
1 Answer
Steven Parker
231,271 PointsFor future questions, take a look at these videos about using Markdown formatting to preserve the code's appearance, and sharing a snapshot of your workspace.
But after guessing about the formatting, these issues are still apparent:
- you can't define a variable twice (first
let randomRGB;
and laterconst randomRGB ...
) - creating the color outside the loop will cause every created element to have the same color
- the separators between clauses in a "for" loop must be semicolons, not commas
- referencing a string as its own statement (
randomRGB;
) doesn't cause any action
TIP: A little experimentation in the workspace will help you find issues like these.