An7hony Posted November 8, 2011 Share Posted November 8, 2011 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); } } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 8, 2011 Share Posted November 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
An7hony Posted November 8, 2011 Author Share Posted November 8, 2011 thanks!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.