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

Need Help Please

Add an else clause to complete the conditional statement. Inside the else clause add another alert that says "JavaScript is the best language!"

My code...

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

What am I doing wrong here? Thanks

4 Answers

Just remove the "=" from the Alerts:

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

But also within the alert function the html p tags may not be necessary

I was gonna say the same thing. Good job

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

Hey Dana

try removing the paragraph tags and tell me if that works

It passed with the paragraph tags, I just needed to remove the "=". I used the paragraph tags because that's the way the video tut was showing it. Thanks guys.