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 Foundations Numbers Operators

Chris Martinez
Chris Martinez
11,715 Points

how do i separate the variables?

my understanding is that each variable needs to be separated by a comma when listing in this manner, but i can't seem to work a comma into my set without getting "parse error". i've tried three = a + b,
and three = (a+b), but neither are passing. the only method that passes is simply three = a + b
without a comma. and i can pass the subsequent variable tasks without the comma as well. how does the computer know they are separate variables?

Chris,

I just went back and found the lesson that I believe you're asking about....

In this situation, you aren't listing out your variables in a way that you would need them separated with a comma. You're adding(concatenating) the values of the variables to create a new value for the variable "three".

Still confused? Yeah, it's hard to explain..... But I'll try my best.

In the example:

var a =1, b = 2, c = 4;

You're declaring 3 different variables, and that's why you need each one separated with a comma. If there were no commas, the computer would think "Ok, this guy wants one variable that says 'a = 1 b = 2 c = 4'" The commas tell the browser that that is the end of the variable, and that now it wants to create a new one following the comma.

After you've declared the variables as listed in the example, you can call them out in your code. If you're using an operator(+) in between the variables, it tells the browser that you want to add the values together(if they're both numbers). There is no need for a comma if you're using operators to do math or concatenate strings. In fact, it will normally cause an error, as you've found.

I hope this helps. If you're still confused, let me know what you're confused about, and I'll try my best to clarify.

-Brent

1 Answer

For this challenge you can just write each variable on its own line with a semi-colon at the end. No need to chain them together. For example:

var three = a + b;
var one = a;
var two = b;

To make a list of variables you just separate each one with a comma as per the example in the code challenge:

var a = 1,
       b = 2,
       c = 4;

Hope this helps! :)