Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Introducing Conditional Statements

Kosuke Kondo
Kosuke Kondo
1,235 Points

Q:Add an else clause to complete the conditional statement. Inside the else clause add another alert that says "JavaScri

Could you give me correct code for this question?

app.js
var answer = prompt('What is the best programming language?');
if (answer === 'JavaScript') {
  alert("You are correct");   
} else {
  alert("JavaScript is the best language!");
];
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
Kosuke Kondo
Kosuke Kondo
1,235 Points

Here's my current code.

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

5 Answers

Kosuke Kondo
Kosuke Kondo
1,235 Points

Thanks, jose! :) I had a syntax error, but (answer === 'javascript') was correct. I'm glad if you keep help for us!

Jose Linares
Jose Linares
5,062 Points

Oh really? I did not know that javascript uses 3 equals signs to compare elements. I googled it and you are right, sorry about that.

Kosuke Kondo
Kosuke Kondo
1,235 Points

No worries! Thank you for your quick response! It's so helpful! :D

Sobin Sebastian
Sobin Sebastian
5,348 Points

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!"); }

Jose Linares
Jose Linares
5,062 Points

I think you have a syntax error, it is (answer == 'javascript') not (answer === 'javascript'). Two equals sign are used to compare elements, three equals signs like you used is a systax error.

Jose Linares
Jose Linares
5,062 Points

You also have more syntax errors, your code should be like this:

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