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

Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Conditional statements

What is wrong with this? The code challenge checker keeps saying I've done something wrong.

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

app.js
var answer = prompt('What is the best programming language?');
if ( answer==='Javascript' ) {
  alert('You are 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>

3 Answers

The question states: Add a conditional statement that opens an alert dialog box with the message "You are correct" when the answer contains the string 'JavaScript'.

The error is on line two:

if ( answer==='Javascript' ) {

It should rather be 'JavaScript' with a capital letter 'S' and not 'Javascript' as in your current code.

Cheers!

Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Dang. I read over that again and again and didn't notice the case difference. Thanks for helping out!

Ben Brenton
Ben Brenton
266 Points

It's been a while since I covered JS basics, but I think your second line in the .js file holds the problem. The '===' needs to be separated from the other words.

Nathan Llewellyn
Nathan Llewellyn
2,090 Points

Hmm...I just tried that and it still says I'm getting it wrong. The program actually runs as intended first showing a prompt and then an alert box if I answer with 'Javascript'. Even though the program runs it is still marked as wrong.

Kishan S
Kishan S
15,410 Points

It is syntactically correct. check your alert, prompt, if values. Is it equal to what treehouse says you should get?