Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.