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

Jeremy Barbe
Jeremy Barbe
8,728 Points

Everything seems to be in order...

I've even looked at other questions concerning this challenge and everything seems to match up. Yet, it's still coming up as incorrect. What am I doing wrong?

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>

2 Answers

Alex Heil
Alex Heil
53,547 Points

hey Jeremy Barbe , you're actually pretty close with your code already but the last part of the else statement has the wrong syntax (probably typo):

1) you currently close the alert in the else statement with a curly bracket, this should be a normal bracket instead (the same way you correctly used it on the other statements).

2) after the alert you also want to end the else block - there you now need a curly bracket which is currently missing from the code you posted.

at the end the whole code block would correctly look 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!');
}

hope that helps and have a nice day ;)