function call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philip WATTS

    function call

    Can anyone help me with the following code. What ever entry I make for
    variable "year" the function excecuted is "checkleapd ays" 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 "checkleapd ays" function is
    called.

    Any advise?

    Code

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



  • Lasse Reichstein Nielsen

    #2
    Re: function call

    "Philip WATTS" <PRWATTS@syring a.freeserve.co. uk> writes:
    [color=blue]
    > Can anyone help me with the following code. What ever entry I make for
    > variable "year" the function excecuted is "checkleapd ays" and not
    > "checkdays" .[/color]

    Are you sure? I would have expected it to always call "checkdays" .
    [color=blue]
    > if (leap=0){[/color]

    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 - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Hywel Jenkins

      #3
      Re: function call

      In article <blscuf$iai$1@n ews7.svr.pol.co .uk>,
      PRWATTS@syringa .freeserve.co.u k says...[color=blue]
      > Can anyone help me with the following code. What ever entry I make for
      > variable "year" the function excecuted is "checkleapd ays" 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 "checkleapd ays" function is
      > called.
      >
      > Any advise?
      >
      > Code
      >
      > var leap=year % 4
      > alert(leap)
      > if (leap=0){
      > checkleapdays(d ay,month)
      > }
      > else{
      > checkdays(day,m onth)}[/color]

      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


      Comment

      • Dr John Stockton

        #4
        Re: function call

        JRS: In article <blscuf$iai$1@n ews7.svr.pol.co .uk>, seen in
        news:comp.lang. javascript, Philip WATTS <PRWATTS@syring a.freeserve.co. uk[color=blue]
        > 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 "checkleapd ays" 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 "checkleapd ays" function is
        >called.
        >
        >Any advise?
        >
        >Code
        >
        >var leap=year % 4
        >alert(leap)
        >if (leap=0){
        >checkleapdays( day,month)
        >}
        >else{
        >checkdays(day, month)}[/color]

        (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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

        Comment

        Working...