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, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge

Javascript

why add а comma between each colors ? rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; why the code does not work that way? rgbColor = 'rgb(' + red + green + blue ')';

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

Iliya,

If you didn't have commas separating your arguments, the method would have no way of telling them apart, and would read it as one long argument.

The commas help to separate ideas, just as in regular language.

Erik

Thanks for the answer. I have another question.Why the quotes in this code ? html += '<div style="background-color:' + rgbColor + '"></div>';

Erik McClintock
Erik McClintock
45,783 Points

Iliya,

Quotation marks, whether single or double, are used to create a data type called a "string", which is text. If you need some more refreshing on syntax and punctuation and their uses in code, I highly recommend going back to basic, beginner videos and rewatching until this information sinks in and sticks. You will have a very difficult time moving forward if you have yet to learn these core principles and ways of doing things. They are absolutely necessary for writing any sort of code, so you need to make sure you understand them before progressing.

Erik