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

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