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

Ryan Sarda
Ryan Sarda
4,052 Points

Can you help me with my JavaScript Basics 'Else' Clauses?

I am on JavaScript Basics Stage 4 (Making Decisions with Conditional Statements) and I am struggling with these 'else' clauses that come after the 'if' clause. I'm on the code challenge for this part of the course and am on step 3 of 3.

The question states to: Add an else clause to complete the conditional statement. Inside the else clause add another alert that says "JavaScript".

Whenever I do that, it says that my 'Task One is no longer passing' and then I have to start all over. My code is below. 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>

4 Answers

Ethan Lowry
PLUS
Ethan Lowry
Courses Plus Student 7,323 Points

Hey Ryan,

You shouldn't have the semicolon following the condition of the if statement. This is probably what's causing you issues.

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

Hi Ryan,

The if statement is looking for a boolean ( true /false) , and you provided it, with the ===. I just wonder if it is looking for another condition after the else, as in !== . I'm trying to remember that section. Maybe this helped? Best of luck.

Ryan Sarda
Ryan Sarda
4,052 Points

Hi Ethan,

That was the problem. Can't believe I made that rookie mistake!

Thanks!