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

Kathryn Kassapides
Kathryn Kassapides
9,260 Points

Why exactly do you have to change 'Mercury' to 'MERCURY' after you place the .toUpperCase?

And how does it know that any the answer 'mercury' typed anyway is correct? For example, MerCurY or mercury or MERCURy? if (answer.toUpperCase() === 'MERCURY'() { console.log (Sorry, your incorrect); }

1 Answer

Hi Kathryn

In this example we convert the user input to all uppercase letters so that we could compare it with the word 'MERCURY' which is the correct answer. We do not know upfront what the user will give us as an input. The user can even give us 'Mercury' or 'mercury' or 'MERCURY', too. I am new to JavaScript and just learning myself but I don't think the program itself really cares about 'Mercury' or 'mercury' or 'MERCURY' - it will transform the string to uppercase anyway and make the comparison.

In order to evalute this condition if (answer.toUpperCase() === 'MERCURY') to true the user input must match with the answer (in this case 'MERCURY').

So the short answer is that we need to test if a response is correct and we can do this with the toUpperCase()-method.

I hope this makes sense!