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

Introducing Conditional Statements

For the if/else statement, couldn't you do this instead of doing the .toUpperCase:

if (answer === 'Ruby' || answer === 'ruby') {

} else {

}

This is so that only one of the conditions have to match when the user puts in ruby or Ruby.

for example,

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

if (answer === 'JavaScript' || answer === 'javascript' || answer === 'javaScript' || answer === 'Javascript') {

alert('You are right!');

}

else {

alert('You are wrong!'); }

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

Well you would be correct...for that specific permutation. However, there can be multiple case possibilities and permutations in this, let me list a few:

  • Ruby
  • rUby
  • RUbY
  • RUBy
  • RUBY

I think you are getting the point right? There are way to many permutations for you to consider in just a simple if statement. However, if you simply make all the letters uppercase or lowercase then you only have one permutation to check for. That's why we use the .toUpperCase or .toLowerCase when checking for case sensitivity because it reduces the number of possible combinations/permutations to just 1.

I get it, it is more efficient to use the .toUpperCase and.toLowerCase because there are so many variations.