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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge

The OR || operator doesn't work on this project, why?

I tried to add the || to a quiz to give my user two options but when I use it even if I put the wrong answer it counts it as correct. When I take off the second option it works fine. Can I not use the || operator in this instance? let myAngeles = prompt( `Easy start to the quiz ${myName}, give me any NFL team from LA?` ); if (myAngeles.toUpperCase() === `RAMS` || `CHARGERS`) { myScore += 20; }

4 Answers

let myAngeles;
const myAngelesPrompt = () => {
  myAngeles = prompt( `Easy start to the quiz ${myName}, give me any NFL team from LA?` ); 
  if(myAngeles.toUpperCase() === `RAMS` || myAngeles.toUpperCase() === `CHARGERS`) { 
    myScore += 20; 
  }
}

I'm not 100% sure if this is the correct fix since I haven't played around with prompts too often, but lmk if it doesn't work.

You may have been using this code inside a function and did not add that part of your code but the || operator should work as I have it above, or you could wrap your answers in parenthesis as well

if(myAngeles.toUpperCase() === (`RAMS` || `CHARGERS`)) { 
    myScore += 20; 
}

I believe the problem is with this part if (myAngeles.toUpperCase() === 'RAMS' || 'CHARGERS'). The two conditions separated by the || are myAngeles.toUpperCase() === 'RAMS' and just 'CHARGERS', not myAngeles.toUpperCase() === 'CHARGERS'. And the boolean value of any non-zero value is true, so essentially the condition you put was myAngeles.toUpperCase() === 'RAMS' || TRUE, which will always be true.

Thanks, Joseph! I see what I did wrong now.

Thank you Joseph for explaining what I was trying to show! I got too caught up in trying to write up the code and forgot to give an explanation. Yours was perfect!

Thanks so much, Jordan! That worked 😃😃😃😃

Ohhh actually the 2nd one was a more concise solution.