getDay question

G

GSN

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_timestamp.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?
 
E

Erwin Moller

GSN wrote:

Hi GSN,
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_timestamp.getDay();

I do the following:


if (this_weekday > 4 || this_weekday = 0)

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

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

== for comparison
= for assignment

Good luck,

Regards,
Erwin Moller
 
R

RobB

GSN said:
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_timestamp.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?

http://d0om.fnal.gov/d0admin/doctaur/dtdocs/p-langs/web_prog_bookshelf/jscript/ch05_04.htm
 
M

Mick White

GSN said:
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_timestamp.getDay();

I do the following:


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

{
//do something else
};


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

Mick
 
F

Fred Oz

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

Mick

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 )
 

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
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top