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

Derek Dorazio
Derek Dorazio
1,004 Points

Bugged code on "Introducing Conditional Statements: 3 objectives" quiz.

Just wanted to point out that I was stuck on Challenge 2 of 3 for at least 15 minutes before I had to ask a friend what was going on and why I couldn't figure out the Challenge task 3 of 3.

The code was:

var answer = prompt("What is the best programming language?");
if ( answer === "JavaScript" ); {
  alert("You are correct");
}

It said "You are correct!" and let me move on. But when I had left that code (assuming it was correct) it proceeded to add the else command which led to:

var answer = prompt("What is the best programming language?");
if ( answer === "JavaScript" ); {
  alert("You are correct");
} else {
  alert("JavaScript is the best language!");
}

And that didn't work. So needless to say as a beginner, I was highly confused.

2 Answers

Antony .
Antony .
2,824 Points

if ( answer === "JavaScript" ); {

Hint: ;

Derek Dorazio
Derek Dorazio
1,004 Points

Yeah, what I was trying to understand if I didn't explain it correctly was why did the first code work on challenge 2 of 3, but it didn't on challenge 3 of 3.

That is what I'm trying to understand.

if ( answer === "JavaScript" ); {

How does this work the first time, but not the second time? (I understand that the semi-colon was the issue, as I was able to finally figure it out after asking a friend.)

Antony .
Antony .
2,824 Points

Yea I understand, that's really weird. It looks like there's a bug with the second challenge. That code should have not passed at all.

Antony .
Antony .
2,824 Points

I'll go ahead and submit this to a moderator for further action.

Derek Dorazio
Derek Dorazio
1,004 Points

Awesome. I just didn't want anyone to get caught up in confusion if that was to happen to them as well.

Thanks for the quick responses.