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 trialKosuke Kondo
1,235 PointsQ: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?
var answer = prompt('What is the best programming language?');
if (answer === 'JavaScript') {
alert("You are correct");
} else {
alert("JavaScript is the best language!");
];
<!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>
5 Answers
Kosuke Kondo
1,235 PointsThanks, jose! :) I had a syntax error, but (answer === 'javascript') was correct. I'm glad if you keep help for us!
Jose Linares
5,062 PointsOh 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
1,235 PointsNo worries! Thank you for your quick response! It's so helpful! :D
Sobin Sebastian
5,348 Pointsthe 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
5,062 PointsI 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
5,062 PointsYou 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!"); }
Kosuke Kondo
1,235 PointsKosuke Kondo
1,235 PointsHere'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!"); ];