Using the logical OR operator || in if statements

Hi!
I’m just starting out with Javascript and experimenting with the OR operator in if statements. I’ve written the following code:

let day = ‘Saturday’;

if (day === “Monday” || “Tuesday” || “Wednesday” || “Thursday” || “Friday”){
console.log(“It’s a work day.”);
} else if (day === “Saturday” || “Sunday”) {
console.log(“It’s the weekend.”)
}

But this prints “It’s a work day.” to the console - I can’t figure out why. Is the syntax incorrect? Or am I misusing the || operator?

Thanks!

Hello, and welcome to the forums!

Each of the OR conditions is checked separately so you’ll need to include the day === part for each comparison.

The reason you didn’t get a syntax error is because what you wrote is valid, it just doesn’t do what you want. As you continue the lessons, you’ll learn about truthy values. In this case, “Tuesday” by itself evaluated as truthy so it met the condition. If we make it day === "Tuesday", then it is false.

1 Like

Thanks for the clear explanation! It makes sense now :slight_smile: