Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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