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

Nicholas Lievens
Nicholas Lievens
8,624 Points

Can't pass challenge in Chrome?

I've made following code

var answer = prompt('What is the best programming language?');
if(answer){
    if( answer.toUpperCase() === 'JAVASCRIPT' ) {
        alert('You are correct');
    } else {
        alert('nest');
    }
}

Normally it didn't need if(answer) first when following the video tutorial but when not adding this you get an error in Chrome. Then when needing to do the equals JAVASCRIPT part the test will report it's not OK while it really is... I think this validation should be fixed by TeamTreeHouse?

3 Answers

Jake Lundberg
Jake Lundberg
13,965 Points

Here is the answer, I just passed the challenge with this code:

var answer = prompt('What is the best programming language?');

 if( answer === 'JavaScript' ) {
        alert('You are correct');
    } else {
        alert('JavaScript is the best language!');
    }

unless you are referring to a different challenge...but this is the answer to the challenge that this post is linked to...

Nicholas Lievens
Nicholas Lievens
8,624 Points

Indeed this works, I see where I went wrong. Instead of comparing to JavaScript I compared to Javascript and then the Bummer message told me 'Comparing strings is case sensitive. So 'Javascript' or 'javascript' is not equal to 'JavaScript'. That's why I started using the toUpperCase() etc.

But thanks to your solution I saw the S was also in uppercase. Thanks

jason chan
jason chan
31,009 Points
var answer = prompt('What is the best programming language?');

 if( answer === 'JavaScript' ) {
        alert('You are correct');
    } else {
        alert('JavaScript is the best language!');
    }

That's all you need.

Nicholas Lievens
Nicholas Lievens
8,624 Points

I know this should be the answer but it isn't, I exactly copied your and it does not pass . It will say that Task 1 is not correct anymore and when using Developer tools you'll see there's an error

Jake Lundberg
Jake Lundberg
13,965 Points

You dont need if(answer), or toUpperCase() per the challenge instructions... All they want you to do is test if the answer is equal 'JavaScript'...if it is, then alert 'You are correct', if not, then alert 'JavaScript is the best language'. You are adding a little more than they wanted you too.