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 trialRichard Schiller
9,238 PointsCan anyone help men with this bit if if/else syntax?
It says that my first line is wrong when I add the else block
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>
Akash Sharma
Full Stack JavaScript Techdegree Student 14,147 PointsIts a syntax error so you should be looking for proper quotes, methods being written correctly etc. and in your case all brackets must opened and closed.
var answer = prompt ("What is the best programming language?");
if (answer === "JavaScript") {
alert("You are correct");
}
else {
alert("JavaScript is the best language!");
}
2 Answers
Steven Parker
231,271 PointsYou have unmatched braces. It looks like you accidentally erased the closing brace after the first alert.
Just restore that character and you'll pass the challenge.
Tsenko Aleksiev
3,819 PointsAs the people said "{" is missing but note that if the user writes the input in lower case or in upper case it ill not work as it should, I would include a new var that converts the input into all upper/lower case and do the if statement. Best regards! :)
Marco Poletto
Courses Plus Student 10,099 PointsMarco Poletto
Courses Plus Student 10,099 PointsYou are missing a "}" before else ...... } else { .....