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 trialArink Bertrand
10,165 Pointsaddition gives a combined number
so when I do message += num1 + " + " + num2 + " = " + (num1 + num2); lets say num1 is 5 and num2 is 6, I get the total as 56. even with the parentheses in place. Everything else works, if I change the + to * or / or - it works fine.
2 Answers
Elena Man
21,092 Points"+" has two uses. One is addition, the other however is string concatenation. If one or both of your variables is a string, then + will concatenate them.
You will need to use parseInt or parseFloat to turn a string into a number.
Dmitry Polyakov
4,989 PointsIt means that your numbers are not really numbers... they are strings. Strings are just concatenated.