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

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

var answer prompt('what is the best programming language?'); alert ("You are correct"); if (answer === 'JavaScript') { (" That's right!"); } else { (" That's wrong!"); } else { alert("JavaScript is not the best language!"); (" That's true!"); }

app.js
var answer 
prompt('what is the best programming language?');
alert ("You are correct");
if (answer === 'JavaScript') {
  (" That's right!");
} else {
  (" That's wrong!");
} else {
alert("JavaScript is not the best language!");
   (" That's wrong!");
}
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

Antti Lylander
Antti Lylander
9,686 Points

Only do what the instructions ask and nothing else. The first task's instructions are a bit vague though, but it is intended that you assing the prompt to answer

var answer 
prompt('what is the best programming language?'); //you should assing this to answer
alert ("You are correct"); //now this will show the alert anyway after prompt has closed. Delete this row.
if (answer === 'JavaScript') {
  (" That's right!"); //as per instructions, you should say 'You are correct'
} else {
  (" That's wrong!"); //here you should say "JavaScript is the best language!"
} else { //you cannot have two times else, delete this block
alert("JavaScript is not the best language!"); 
   (" That's wrong!");
}
Steven Parker
Steven Parker
231,271 Points

I see a few issues:

  • you must assign ("=") the result of calling "prompt" to the "answer" variable to test it later
  • putting parentheses around a string doesn't do anything by itself, did you mean to call "alert"?
  • you can only have one "else" in an "if ... else" sequence
  • some of these strings are not in the instructions