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 The Conditional Challenge Solution

toUpperCase in chrome console is not working whereas with parentheses i.e. toUpperCase() works just fine. Why so?

Please check my code:

var correct = 0; var ans1 = prompt("Name the programming language that is also a gem."); if (ans1.toUpperCase === 'RUBY'){ document.write("it is correct"); correct += 1; } else { document.write ("it is wrong."); } console.log(correct);

the code is not working till i add () as given in the Mozilla reference. Once added, works just fine:

var correct = 0; var ans1 = prompt("Name the programming language that is also a gem."); if (ans1.toUpperCase() === 'RUBY'){ document.write("it is correct"); correct += 1; } else { document.write ("it is wrong."); }

console.log(correct);

please help me understand why is this problem occurring and what is correct method.

4 Answers

The method .toUpperCase() requires the parenthesis because it is part of its syntax.

In that case, there should be a note in video or teachers note regarding the same.

Oh there is, Karan!

The syntax of methods/functions was explained when f. e. the Math.floor() and Math.random() methods were introduced. And also when we first learned the .toUpperCase() method in one of the first videos, where we actually learned about the method and what it does. You are already at the conditional challenge.... maybe you simply forgot about it ;)

yup. thank you so much for clearing things up. :)