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

The quiz asks for a conditional statement. What is a conditional statement if not an "IF" statement?

I put in an "IF" statement and get an error that the "first part of the question is now wrong". The problem is I don't understand what the test expects me to do next. I can put in a thousand different solutions.

app.js
var answer = prompt("What is the best programming language?");
if (answer.toUpperCase() === 'JAVASCRIPT') {
  alert('You are correct');}
else {
alert('Not correct');
}
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>

Hi, it looks like your else clause is not printing what they asked for. These challenges can be picky about that kind of stuff. Also your code looks like it would work in real life. But also they were looking for answer === "JavaScript" not javascript converted to upper case... Like I said what you did makes perfect sense. It's just not what they were looking for

Lowell, what I do whenever possible is copy and paste the string parts of challenges from the question into the answer. That way when I get it wrong it's probably my logic and not a typo. As far as the "task one is no longer passing"... That is misleading. It usually just mean you got something wrong on the current task. (unless you deleted the first task)

3 Answers

var answer = prompt("What is the best programming language?")
if (answer === "JavaScript") {
  alert("You are correct");
} else {
  alert("JavaScript is the best language!")
}
Josh Salyer
Josh Salyer
7,265 Points

Well the question asks you to specifically create a conditional statement that checks if the text entered in the prompt is equal to "JavaScript". If it is then alert the user with the message "You are correct". If it isn't "JavaScript", then alert the user with the message "JavaScript is the best language!". So your answer might be something like:

var answer = prompt("What is the best programming language?");
if (answer === "JavaScript") {
  alert("You are correct");
} else {
  alert("JavaScript is the best language!");
}

Sometimes with these challenges, you just need to phrase things exactly as they ask. Hope that helps!

Sakis Stefanopoulos
Sakis Stefanopoulos
1,073 Points

var answer = prompt('What is the best programming language?'); if ( answer === 'JavaScript' ); { alert("You are correct"); } else { alert("JavaScript is the best language!"); } I can't procced. It says that i have a syntax error but i can't find it