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 (Retired) Making Decisions with Conditional Statements The Conditional Challenge

Justin Houghton
Justin Houghton
4,560 Points

Could someone explain to me where I went wrong with this conditional statement?

//question 1

var questionOne = prompt ('What is your name?');

if (questionOne = 'Justin') {
    document.write ('You are right!');
} else {
 document.write ('You are wrong!'); 
}

No matter what I type in the prompt, I still see "You are right".

1 Answer

In JavaScript, equality comparisons are done using either == or ===. Using a single = sign assigns the value on the right of the symbol to the variable on the left of the symbol. Therefore you are assigning questionOne the value of Justin

Try using ===

Justin Houghton
Justin Houghton
4,560 Points

oh wow, that's embarrassing. I can't believe I didn't catch that. Thank you!