&& and || do not group the way you think they do.
(a && b || c) === ((a && b) || c)
You've written your conditional assuming it would be (a && (b || c))
So...
var curYear = 2014;
var ListYr = "2015";
var month = "Apr";
var isTrue = (curYear == ListYr && month == "Jan" || month == "Feb" || month == "Mar" || month == "Apr" || month == "May" || month == "Jun" || month == "Jul" || month == "Aug" || month == "Sep");
isTrue evaluates to true because...
curYear == ListYr && month == "Jan" --> false
month == "Feb" --> false
month == "Mar" --> false
month == "Apr" --> true
month == "May" --> false
month == "Jun" --> false
month == "Jul" --> false
month == "Aug" --> false
month == "Sep" --> false
false || false || false || true || false || false || false || false || false -> true
You want...
(curYear == ListYr && (month == "Jan" || month == "Feb" || month == "Mar" || month == "Apr" || month == "May" || month == "Jun" || month == "Jul" || month == "Aug" || month == "Sep"))
More detail:
On Mon, Jun 2, 2014 at 11:53 AM, I.O.S <isogunro@gmail.com> wrote:
--Can someone please help me with my javascript within the jsfiddle below?I need to make sure certain dates fit within the current fiscal year (ie. Oct. 2013 - Sep. 2014)For some reason, my script isn't working. It has (Apr. 2015) within the current fiscal year.http://jsfiddle.net/4DFUL/12/
Thanks for any help you can provide.
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.