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

Can anyone help men with this bit if if/else syntax?

It says that my first line is wrong when I add the else block

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>
Marco Poletto
Marco Poletto
Courses Plus Student 10,099 Points

You are missing a "}" before else ...... } else { .....

Akash Sharma
seal-mask
.a{fill-rule:evenodd;}techdegree
Akash Sharma
Full Stack JavaScript Techdegree Student 14,147 Points

Its 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
Steven Parker
231,269 Points

You 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
Tsenko Aleksiev
3,819 Points

As 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! :)