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 Introducing Conditional Statements

Add a conditional statment that opens an alert dialog box

Add a conditional statement that opens an alert dialog box when answer is the string

var answer=prompt('What is the best programming language);
if(answer==='you are correct') {opens an alert dialog box
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="app.js"></script>

2 Answers

You have to check whether the string is equal to 'JavaScript' and alert 'You are correct' if it is.

So, you need an if statement:

if (answer === 'JavaScript') {
  alert ('You are correct');

You need to close the string inside the alert() method.

And you need to use === triple equals for the comparison.



I agree about the missing ' doh! But the == will work as well as they are both strings.

Agree in principle but in this context, i.e. passing the challenge, we need to use triple equals. It's part of the challenge tests. :wink: :+1:

OK, understood. Updated. Thanks for the feedback.


Hi there,

You haven't closed the string in the first line; add a ' after the word 'language' and before the bracket.

Next, you want to see if the answer is 'JavaScript'. If it is, use the alert() method to prompt the user with the message 'You are correct'. Pass that string into the alert() method by putting it inside the brackets.