getDay question

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

    getDay question

    I am trying to get something to happen if the day is either Friday,
    Saturday or Sunday. So after creating a variable from getDay...

    var this_weekday = this_date_times tamp.getDay();

    I do the following:


    if (this_weekday > 4 || this_weekday = 0)
    {
    //do something
    }
    else

    {
    //do something else
    };

    It isn't working. It works fine if I just write "if (this_weekday = 4
    )" or "if (this_weekday > 4 )" but when trying to get use OR (||) I am
    having no luck. Can someone help me with the proper syntax?

  • Erwin Moller

    #2
    Re: getDay question

    GSN wrote:

    Hi GSN,
    [color=blue]
    > I am trying to get something to happen if the day is either Friday,
    > Saturday or Sunday. So after creating a variable from getDay...
    >
    > var this_weekday = this_date_times tamp.getDay();
    >
    > I do the following:
    >
    >
    > if (this_weekday > 4 || this_weekday = 0)[/color]

    if ( (this_weekday > 4) || (this_weekday == 0))

    might do the trick.
    mind the == instead of =

    == for comparison
    = for assignment

    Good luck,

    Regards,
    Erwin Moller

    Comment

    • RobB

      #3
      Re: getDay question

      GSN wrote:[color=blue]
      > I am trying to get something to happen if the day is either Friday,
      > Saturday or Sunday. So after creating a variable from getDay...
      >
      > var this_weekday = this_date_times tamp.getDay();
      >
      > I do the following:
      >
      >
      > if (this_weekday > 4 || this_weekday = 0)
      > {
      > //do something
      > }
      > else
      >
      > {
      > //do something else
      > };
      >
      > It isn't working. It works fine if I just write "if (this_weekday = 4
      > )" or "if (this_weekday > 4 )" but when trying to get use OR (||) I[/color]
      am[color=blue]
      > having no luck. Can someone help me with the proper syntax?[/color]



      Comment

      • Mick White

        #4
        Re: getDay question

        GSN wrote:
        [color=blue]
        > I am trying to get something to happen if the day is either Friday,
        > Saturday or Sunday. So after creating a variable from getDay...
        >
        > var this_weekday = this_date_times tamp.getDay();
        >
        > I do the following:
        >
        >
        > if (this_weekday > 4 || this_weekday = 0)
        > {
        > //do something
        > }
        > else
        >
        > {
        > //do something else
        > };[/color]


        if (this_weekday > 4 || this_weekday == 0)
        {
        //do something
        }
        else
        {
        //do something else
        };

        Mick


        Comment

        • Fred Oz

          #5
          Re: getDay question

          Mick White wrote:[color=blue]
          > GSN wrote:
          >[color=green]
          >> I am trying to get something to happen if the day is either Friday,
          >> Saturday or Sunday. So after creating a variable from getDay...
          >>
          >> var this_weekday = this_date_times tamp.getDay();
          >>
          >> I do the following:
          >>
          >>
          >> if (this_weekday > 4 || this_weekday = 0)
          >> {
          >> //do something
          >> }
          >> else
          >>
          >> {
          >> //do something else
          >> };[/color]
          >
          >
          >
          > if (this_weekday > 4 || this_weekday == 0)
          > {
          > //do something
          > }
          > else
          > {
          > //do something else
          > };
          >
          > Mick
          >[/color]

          Hence why it is suggested that such tests be written the other way
          around:


          if ( this_weekday = 0 )

          will always return true and not throw an error, making it hard to
          find. Alternatively:


          if ( 0 = this_weekday )

          will always throw an error and force you to fix it with:


          if ( 0 == this_weekday )



          --
          Fred

          Comment

          Working...