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 Working with 'for' Loops The Refactor Challenge – Duplicate Code

Code Execution Issue

Hello. I've written the code exactly as you show in the video, but the browser is giving me a runtime error. Could this have something to do with my browser? I live in Spain.

My code is:

let html = '';

const randomValue = () => Math.floor(Math.random() * 256);

function randomRGB (value) { const color = rgb( ${value()},${value()},${value()} ); return color;

for (let i=1; i<=10; i++) { html += <div style='background-color:${randomRGB(randomValue)}'>${i}</div>; }

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

And the console error is: Uncaught SyntaxError: Unexpected end of input (script.js:13)

Maybe there is an error in the code that I'm not able to see.

Thanks for your help.

Best regards.

1 Answer

Torben Korb
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Torben Korb
Front End Web Development Techdegree Graduate 91,433 Points

Hello Isabel,

It appears that your code is missing an ending curly brace in your randomRGB function, directly after the return color; statement. This is a common mistake that even experienced programmers make. Don't fret; there are tools to help you catch these errors. For instance, in VSCode with linting enabled, you can have it automatically detect and flag missing braces.

Furthermore, consider wrapping your code in triple backticks (`) when posting it. This makes the code more readable and easier to spot issues like missing braces.

I hope this helps. Happy coding!

Thank you very much! :)