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 trialIris Wang
Front End Web Development Techdegree Student 8,288 PointsJavascript basics 'if else' condition statements
var answer = prompt('What is the best programming language?'); if (answer.toUpperCase() === 'JAVASCRIPT') { alert('You are correct'); }
In this code challenge, why is it after I typed the 'if ' statement, the code engine tells me my first statement is no longer passing? But the code still runs in the browser.
var answer = prompt('What is the best programming language?');
if (answer.toUpperCase() === '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
Leslie Heinzen
26,662 PointsHi Iris,
While your code works just fine, the second part of the challenge is asking for the very particular case-sensitivity of 'JavaScript' in the conditional of your if statement, so try that:
if (answer === 'JavaScript'){
alert('You are correct!');
}
That should work.
Happy coding.
Leslie
Apexa Patel
2,287 PointsHello Iris,
I tried it out on jsbin and it works - i added else and just works fine. There may be a bug in this platform. See below!
Iris Wang
Front End Web Development Techdegree Student 8,288 PointsThank you so much for all your help! It was useful! Thanks!
Iris Wang
Front End Web Development Techdegree Student 8,288 PointsIris Wang
Front End Web Development Techdegree Student 8,288 PointsHi Leslie,
Thank you for your quick reply. But in my code I typed
if ( answer.toUpperCase() === 'JAVASCRIPT') { alert('You are correct'); }
Shouldn't all the casing answers the user type in be converted to uppercase which solved the case-sensetivity issue?
Leslie Heinzen
26,662 PointsLeslie Heinzen
26,662 PointsHi Iris,
This isn't the solution that the challenge is asking for, even though technically that is correct. For example, with your current logic, all of the following responses would pass correctly:
Once .toUpperCase() is called on them, they all become 'JAVASCRIPT'. The challenge is specifically looking for answers that correctly match 'JavaScript', so you must use this condition explicitly in your logic. This is why the challenge isn't passing, even though there is nothing wrong with your code. It's just the way the Treehouse team designed this challenge.