By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

function call

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
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.