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

Matthew Lane
Matthew Lane
1,837 Points

Refactor Challenge Solution

I love the game Opus Magnum, which has you build and program machines to solve assembly puzzles. This exercise immediately me struck the same chord, as Opus Magnum keeps track of both the size and speed of your machines.

In the spirit of the game, I was able to condense the code into the following nine lines.

let html = '';
const randVal = () => Math.floor(Math.random() * 256);
let randRGB = () => `rgb(${randVal()},${randVal()},${randVal()}`;

for (let i = 1; i <= 10; i++) {
 html += `<div style="background-color: ${randRGB()}">${i}</div>`;
}

document.querySelector('main').innerHTML = html;

Really enjoyed refactoring. Cheers.

Steven Parker
Steven Parker
240,995 Points

Interesting coincidence that you and Ismael Sandoval made very similar posts at about the same time.