function call

P

Philip WATTS

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)}
 
L

Lasse Reichstein Nielsen

Philip WATTS said:
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
 
H

Hywel Jenkins

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.
 
D

Dr John Stockton

seen in said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top