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 trialJordan Bester
Full Stack JavaScript Techdegree Student 1,291 PointsWhat 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///
3 Answers
Robert Manolis
Treehouse Guest TeacherHi 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.
Jordan Bester
Full Stack JavaScript Techdegree Student 1,291 PointsThank you Robert!!!
Terfa Nomhwange
2,230 PointsIs the track Full stack JavaScript on treehouse enough to take the The Microsoft Technology Associate (MTA) examination?
Tony Idehen
8,060 Pointset 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)
Forrest Pollard
1,988 PointsForrest Pollard
1,988 PointsHi 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:
Hope this was useful, even though you didnt ask lol