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 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
STAFF
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
8,058 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)