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 Basics Making Decisions in Your Code with Conditional Statements Program Multiple Outcomes

Teacher notes Question: What does the "+" in +guessMore (+guessLess etc..) variable mean?

When going thru the teachers notes I noticed that in the code there was a + in front of the variables guess, guessMore, and guessLess. Can you explain why we would put a + in front of the variable name?

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,341 Points

Hi Jessica. The plus (+) sign is the Unary Plus Operator in Javascript. It attempts to convert the variable to a number. Because we are reading from a prompt the input the user enters will be a string. We want to convert in to a number before comparing it with the correct guess. You can read more about the Unary Plus Operator here. Hope this helps Jessica and good luck on your coding journey.

This does help! Thank you so much for your answer. I have moved on in the track to "Converting strings to Numbers". I wanted to ask if this was a shorthand way of converting a string to a number vs the parseInt()?