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

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