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 trialKevin Jervis
2,600 PointsConditional Statements
Hi Guys
Keep getting this message for some reason: It looks like Task 2 is no longer passing.
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?");
}
<!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
23,100 PointsHi 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
2,600 PointsSorry, 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
23,100 PointsKevin Jervis, Yes best answer is great but you can also click on +1.
Kevin Jervis
2,600 PointsOk cool. All done. Thanks again mate
Kevin Jervis
2,600 PointsKevin Jervis
2,600 PointsHi Bram
That's great thanks for your help. I can see exactly where I went wrong
Bram Pauwelyn
23,100 PointsBram Pauwelyn
23,100 PointsHi Kevin Jervis You're welcome :). Don't forget to upvote my answer.