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

Michael Humenick
Michael Humenick
1,138 Points

Why is this wrong?

What is wrong with this code?

var question = prompt('What is Mickles real name?');

if(question.toUpperCase === Michael){

document.write('You are correct!');

} else() {

document.write('No you stupid idiot');

}

1 Answer

Steven Parker
Steven Parker
231,007 Points

I see a few issues:

  • to invoke the "toUpperCase" method, there must be parentheses () after the name
  • a string literal (like "Michael") must be enclosed in quotes
  • after upper case conversion, only an all-upper-case literal would match ("MICHAEL")
  • a less abusive failure message would probably create a better experience for the user