473,413 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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 2581
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
4
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
9
by: Morten Lemvigh | last post by:
Is it possible to pass a pointer to a constructor or a class definition as argument to a function? Maybe in a way similar to passing function pointers...? The function should construct a number...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.