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

Java The Solution

sebbe12
sebbe12
4,015 Points

Why does " + " and " = " work shouldn't it be the string + and not actually + .

Why does " + " and " = " work shouldn't it be the string + and not actually + . I understand if we use + + it will give us error but why does this work.

1 Answer

Steven Parker
Steven Parker
231,248 Points

It looks like you placed this question in the wrong category. It's about "JavaScript" (not "Java").

This exercise is a bit tricky, as it both does math and also displays math symbols. When you see the symbols inside quotes (like " + "), those symbols are part of the message that will be shown. The system treats them as strings and not as operators.

Then when you see the + symbol itself, it can be two things. When used with strings, it is the concatenation operator and joins the strings together. But when used with two numbers (like num1 + num2) it is the addition operator and adds the two numbers for a total. In this exercise you will see it used all 3 ways on the same line.

I hope that clears up the confusion!