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 trialPaula Simon
8,056 PointsHow can I better understand when to use to.UpperCase vs to.LowerCase on conditional statements?
Hello! I am learning about conditional statements in JavaScript. For this video, Guil uses to.UpperCase for the answer "Mercury". Since it works with both "MERCURY" and "mercury" as answers, why/when would it be appropriate to use to.UpperCase vs. to.LowerCase?
Thanks!
2 Answers
Sean Paulson
6,669 PointstoLowerCase and toUpperCase just return the text to lower or upper case.
say for example you want to end a program if a user types "quit". Well that user could enter "Quit", "qUiT", QUIt" or any other input. So you want to force that input to be lower case because your string you are testing against is lower case.
If you are comparing your user input to a upper case string you would force the user input to be uper case with toUpperCase.
Thats why the example you gave works either way because no matter what the input is toUpperCase will force it to be upper case.
Joseph Yhu
PHP Development Techdegree Graduate 48,638 PointsIt shouldn't matter.
Paula Simon
8,056 PointsPaula Simon
8,056 PointsI see, thank you for explaining that in-depth!