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 trialAli Cenk Gözen
3,226 PointsOR Operator Problem
Hello everyone,
I am trying to implement OR Operator in my challenge. But it would not accept the second and third conditions. Where am I making mistakes?
var answer3 = prompt('What is the date of foundation of Turkish Republic?');
if ( answer3.toUpperCase() === '1923' || answer3 === '29 OCTOBER 1923' || answer3 === 'OCTOBER 1923' ) {
score += 1; } else { score += 0;
2 Answers
ale8k
8,299 PointsHi man, let's format the code first of all so it's more readable :P
var answer3 = prompt('What is the date of foundation of Turkish Republic?');
if ( answer3.toUpperCase() === '1923' || answer3 === '29 OCTOBER 1923' || answer3 === 'OCTOBER 1923' ) {
score += 1;
} else {
score += 0;
Looks like we've found the problem! I've also a couple questions.
var answer3 = prompt('What is the date of foundation of Turkish Republic?');
// on the answer below why are you using .toUpperCase() on a string integer, it has no upper case
// the other two answers should also have .toUpperCase on them as you are using them in capitals
if ( answer3.toUpperCase() === '1923' || answer3 === '29 OCTOBER 1923' || answer3 === 'OCTOBER 1923' ) {
score += 1;
} else {
score += 0; // we need another curly brace to end the else statement :)
} // here
I'm going to implement the changes I've suggested below and show you the end product :)
var answer3 = prompt('What is the date of foundation of Turkish Republic?');
// below from the first answer condition I have removed the empty method and added it to the following two conditions.
// Hope this helps!!
if ( answer3 === '1923' || answer3.toUpperCase() === '29 OCTOBER 1923' || answer3.toUpperCase() === 'OCTOBER 1923' ) {
score += 1;
} else {
score += 0;
}
Ali Cenk Gözen
3,226 PointsThanks for the response, I appreciate it. I understand how I use toUpperCase() method.
ale8k
8,299 PointsNo worries dude. There is also .toLowerCase() which as the name kinda tells, it does the opposite :P. However, for user input I recommend using .toUpperCase() and you'll find out why soon! :P