Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Introducing Conditional Statements

Kevin Jervis
Kevin Jervis
2,600 Points

Conditional Statements

Hi Guys

Keep getting this message for some reason: It looks like Task 2 is no longer passing.

app.js
var answer = "JavaScript";
if (answer.toUpperCase() === "JavaScript") {
  alert ("You are correct");
} else {
  document.write("<p>JavaScript is the best language!</p>");
prompt ("What is the best programming 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>

3 Answers

Bram Pauwelyn
Bram Pauwelyn
23,100 Points

Hi Kevin Jarvis,

I see a couple of things. In the code challenge they ask you to assign the prompt to the variable answer. Also you don't need to convert the string to uppercase in your if condition. And you don't need to use the document.write in your else statement but you need to use an alert().

The correct code should look something 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!");
}
Kevin Jervis
Kevin Jervis
2,600 Points

Hi Bram

That's great thanks for your help. I can see exactly where I went wrong

Bram Pauwelyn
Bram Pauwelyn
23,100 Points

Hi Kevin Jervis You're welcome :). Don't forget to upvote my answer.

Kevin Jervis
Kevin Jervis
2,600 Points

Sorry, I'm new to this game. I selected best answer. By upvote are you referring to the arrows where I can select -1 to 1?

Bram Pauwelyn
Bram Pauwelyn
23,100 Points

Kevin Jervis, Yes best answer is great but you can also click on +1.

Kevin Jervis
Kevin Jervis
2,600 Points

Ok cool. All done. Thanks again mate