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

Keith Greatz
Keith Greatz
4,377 Points

The or operator || in this instance won't work, not sure why.

Hi,

I did try and create an or statement and got it to work but in this example it wont, Im not sure why, thanks for any help.

var answer = prompt("do you agree with me?");
if (answer === "yes" || "no") 
{
    alert("glad you made up your mind")
}
 else {
    alert("you are indecisive");
};

Keiffy101

2 Answers

Grace Kelly
Grace Kelly
33,990 Points

Hi Keith, you need to add the instance of another condition fully after the "||" , like so :

var answer = prompt("do you agree with me?");
if (answer === "yes" || answer === "no") 
{
    alert("glad you made up your mind")
}
 else {
    alert("you are indecisive");
};

that should work now :)

This is correct. you must provide two fully "explained" if conditions that are seperated by one OR.

Keith Greatz
Keith Greatz
4,377 Points

Great stuff my friend, It's been some time i've had issues with this.

Keiffy101