Jump to content

using if and ||


An7hony

Recommended Posts

I'm trying to use the js below to check whether lunch is inputted as 0.25, 0.5, 0.75 or 1.

 

Below is the code. It seams to be working as:  if ((day_object[dayname].lunch) != "0.25"){

but as  if (((((day_object[dayname].lunch) != "0.25") || (day_object[dayname].lunch) != "0.5") || (day_object[dayname].lunch) != "0.75") || (day_object[dayname].lunch) != "1") {

it pulls the alert whatever is inputted.

 

else if ((day_object[dayname].start_hhmm != "")  && (day_object[dayname].finish_hhmm != "") && (day_object[dayname].lunch != "")) {
            if (((((day_object[dayname].lunch) != "0.25") || (day_object[dayname].lunch) != "0.5") || (day_object[dayname].lunch) != "0.75") || (day_object[dayname].lunch) != "1") {
            alert("Check lunch hour 0.25 is 1/4 of an hour. 0.5 is 1/2 an hour. 0.75 is 3/4 of an hour. 1 is 1 hour");
                day_object[dayname] = new oDay(day_object[dayname].dayname, day_object[dayname].start_hhmm, day_object[dayname].finish_hhmm, 0);
            }
        }

Link to comment
https://forums.phpfreaks.com/topic/250690-using-if-and/
Share on other sites

Because you need to use the && (logical AND) operator in that case, not OR. Think about the logic involved. The conditional will always return TRUE when using || because no matter what value you compare, it can only equal one of the values in the conditional.

Link to comment
https://forums.phpfreaks.com/topic/250690-using-if-and/#findComment-1286183
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.