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

Javascript 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.

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

Hi 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

Hi 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?

Hi 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:

'javascript'
'Javascript'
'jAvAsCrIpT'
'JAVAscript'

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.

Apexa Patel
Apexa Patel
2,287 Points

Hello 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!

https://jsbin.com/yegejisaxi/edit?html,js,output

Thank you so much for all your help! It was useful! Thanks!