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 trialJoseph Carrillo
2,137 PointsIntroducing 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
Treehouse Moderator 11,077 PointsWell 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.
Joseph Carrillo
2,137 PointsJoseph Carrillo
2,137 PointsI get it, it is more efficient to use the .toUpperCase and.toLowerCase because there are so many variations.
Dane Parchment
Treehouse Moderator 11,077 PointsDane Parchment
Treehouse Moderator 11,077 PointsExactly!