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

Need help with JavaScript, Introducing Conditional Statements challenge, step 3

I have completed the first two steps of this challenge, but when I add the 'else' statement in step 3, I get an error message saying that step one (the first line of code) is no longer passing.

This is what I have. Can anyone see what is wrong with the else statement?

var answer = prompt ('What is the best programming language?'); if (answer === 'JavaScript') { alert.write ("<p>You are correct</p>"); } else { alert.write ("<p>JavaScript is the best language!</p>"); }

Thank you!

app.js

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>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

If I take your code and copy/paste it it passes the first two challenges. But apparantly it really doesn't want alert.write... it just wants alert. If I remove the .write... it passes! See what I mean here:

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

Thanks! I will try that...

It worked!