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

toUpperCase comparison error

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

if ((answer.toUpperCase()} === 'JavaScript'.toUpperCase()) { alert('You are correct'); }

))) Error says: TypeError: 'null' is not an object (evaluating 'answer.toUpperCase')

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points

Hey! I had a bit of trouble with this when I tried to see what was wrong, too. :)

Challenge text:

Add a conditional statement that opens an alert dialog box with the message "You are correct" when the answer is the string 'JavaScript'.

Take the challenge instructions literally, and don't include calling .toUpperCase() on the answer.

The reason? The code checking the challenge isn't actually using your script (it's not actually typing in 'JavaScript' to answer your question) so what'll happen when the script runs is that the alert box will show up, nothing will be entered, and then the next line will cause an error because you'll be calling .toUpperCase() on nothing at all.

The challenge will check to see that you're comparing the two strings in your if statement and returning the proper result though.

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

if (answer === 'JavaScript') 
    {
         alert('You are correct'); 
    }

Oops! And that is it. Many thanks