469,323 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

function call

Can anyone help me with the following code. What ever entry I make for
variable "year" the function excecuted is "checkleapdays" and not
"checkdays". I know from the alert that leap works out correctly, ie 0 on a
leap year and non-zero otherwise, but always the "checkleapdays" function is
called.

Any advise?

Code

var leap=year % 4
alert(leap)
if (leap=0){
checkleapdays(day,month)
}
else{
checkdays(day,month)}

Jul 20 '05 #1
3 2453
"Philip WATTS" <PR*****@syringa.freeserve.co.uk> writes:
Can anyone help me with the following code. What ever entry I make for
variable "year" the function excecuted is "checkleapdays" and not
"checkdays".
Are you sure? I would have expected it to always call "checkdays".
if (leap=0){


Comparison is the "==" operator. You are *assigning* 0 to the variable
"leap". The value of an assignment is the assigned value, so this is
equivalent to
if (0)
which is again equivalent to
if (false)
That is why I expect the "else" branch to be taken every time.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
In article <bl**********@news7.svr.pol.co.uk>,
PR*****@syringa.freeserve.co.uk says...
Can anyone help me with the following code. What ever entry I make for
variable "year" the function excecuted is "checkleapdays" and not
"checkdays". I know from the alert that leap works out correctly, ie 0 on a
leap year and non-zero otherwise, but always the "checkleapdays" function is
called.

Any advise?

Code

var leap=year % 4
alert(leap)
if (leap=0){
checkleapdays(day,month)
}
else{
checkdays(day,month)}


For checking leap years, that code is slightly out. For example, 1900
is divisible by 4, but wasn't a leap year.

--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #3
JRS: In article <bl**********@news7.svr.pol.co.uk>, seen in
news:comp.lang.javascript, Philip WATTS <PR*****@syringa.freeserve.co.uk
posted at Mon, 6 Oct 2003 19:40:14 :-
Can anyone help me with the following code. What ever entry I make for
variable "year" the function excecuted is "checkleapdays" and not
"checkdays". I know from the alert that leap works out correctly, ie 0 on a
leap year and non-zero otherwise, but always the "checkleapdays" function is
called.

Any advise?

Code

var leap=year % 4
alert(leap)
if (leap=0){
checkleapdays(day,month)
}
else{
checkdays(day,month)}


(leap==0).

But you do not need to write code like that, unless you ate using the
Julian Calendar or some other non-Gregorian one; there is always a
better way of doing it, employing the power of the Date Object.

The following, for example, should determine whether a YMD triple
represents a valid date on the proleptic astronomical Gregorian
calendar, up to AD 275760-09-13. It may only be guaranteed after 1970.
It will be wrong, in MSIE4 at least, for the Year Zero, since new Date
there takes a Y in 0..99 to be in 1900..1999. Otherwise it is probably
OK back to -271821 April 21.
function ValidDate(y, m, d) { // m = 0..11 ; y m d integers
with (new Date(y, m, d))
return ((getMonth()==m) && (getDate()==d)) /* was y, m */ }

Read the FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by JKop | last post: by
2 posts views Thread by laredotornado | last post: by
23 posts views Thread by bluejack | last post: by
21 posts views Thread by dragoncoder | last post: by
3 posts views Thread by Beta What | last post: by
9 posts views Thread by CryptiqueGuy | last post: by
9 posts views Thread by Morten Lemvigh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.