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 trialNathan Llewellyn
2,090 PointsConditional 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!'); }
var answer = prompt('What is the best programming language?');
if ( answer==='Javascript' ) {
alert('You are correct!');
}
<!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
Andrews Gyamfi
Courses Plus Student 15,658 PointsThe 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!
Ben Brenton
266 PointsIt'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
2,090 PointsHmm...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
15,410 PointsIt is syntactically correct. check your alert, prompt, if values. Is it equal to what treehouse says you should get?
Nathan Llewellyn
2,090 PointsNathan Llewellyn
2,090 PointsDang. I read over that again and again and didn't notice the case difference. Thanks for helping out!