Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.