Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements Document Your Code with Comments

What is the + sign next to the guess in the conditional statement? can someone clear this up for me? thank you!

let currentGuess = false; let realUn = prompt("guess a numbah between 1 -10 ? "); const answer = 6;

if (+realUn === answer ) { currentGuess = true alert("uuuu smart!!!") alert("you may enter")

}else { alert("go home dummy") }

/// I made some sample code just for a reference but I'm referring to the top line conditional statement///

Forrest Pollard
Forrest Pollard
1,988 Points

Hi dude. I noticed when you posted your code it looked like this:

let currentGuess = false; let realUn = prompt("guess a numbah between 1 -10 ? "); const answer = 6;

if (+realUn === answer ) { currentGuess = true alert("uuuu smart!!!") alert("you may enter")

}else { alert("go home dummy") }

Just a tip for future questions you might have, you can use three backticks and the word "javascript" (```javascript) like that at the beggining of your code and then another three at the end to close it. By doing this it will format your code to look like this:

let currentGuess = false; let realUn = prompt("guess a numbah between 1 -10 ? "); const answer = 6;

if (+realUn === answer ) { currentGuess = true alert("uuuu smart!!!") alert("you may enter")

}else { alert("go home dummy") }

Hope this was useful, even though you didnt ask lol

3 Answers

Robert Manolis
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Robert Manolis
Treehouse Guest Teacher

Hi Jordan Bester , when you see the addition operator used that way, it becomes a unary operator that attempts to convert a string containing numbers into an actual number type, similar to what the Number() method does. :thumbsup:

Thank you Robert!!!

Is the track Full stack JavaScript on treehouse enough to take the The Microsoft Technology Associate (MTA) examination?

Tony Idehen
Tony Idehen
4,990 Points

et currentGuess = false; let realUn = prompt("guess a numbah between 1 -10 ? "); const answer = 6; if (+realUn === answer ) { currentGuess = true alert("uuuu smart!!!") alert("you may enter") }else { alert("go home dummy") }

The + beside the realUn (+realUn) converts the value of realUn to a numerical number first, then compares the converted number to answer value(6)