Hi, hoping someone could help answer this question for me.
I'm a newbie with javascript, just started learning the basics this week as it will be useful at my new workplace.
Done some minimal coding a long time ago.
I'm wondering about compound statements in javascript, see I was always taught to keep code as short & sweet as possible.
One of the guys where i've started working uses a lot of nested statements for example:
Code:
Today = new date();
DayNumber = Today.getDay();
Hour = Today.getHours();
Minute = Today.getMinutes();
if (DayNumber >=1 && DayNumber <=5)
{
if (Hour >= 8 && Hour <= 19)
{
[var_co] = 'yes'
}
else
{[var_co] = 'no'
}
};
else if (DayNumber == 6)
{
if (Hour >= 8 && Hour <=13)
{
[var_co] = 'yes'
}
else
{
[var_co] = 'no'
}
};
else
{
[var_co] = 'no'
};
Dunno, maybe i'm wrong in my assumptions, being out of the loop for years but would the following compound statement be equivalent to the first one/work in javascript?:
Code:
Today = new date();
DayNumber = Today.getDay();
Hour = Today.getHours();
Minute = Today.getMinutes();
if (((DayNumber >=1 && DayNumber <=5) && (Hour >=8 && Hour <=19))
|| ((DayNumber ==6) && (Hour >=8 && Hour <=13)))
{
[var_co] = 'yes'
};
else
{
[var_co] = 'no'
};
See when the particular piece of scripting needed to be done I (still only learning the basics really) pretty much straight away sketched the solution out as in the second example, i.e
Code:
if (((true) && (true))
or ((true) && (true)))
{yes};
else
{'no'};
Just wondering whether that's correct syntax in javascript.
As I said, i'm still picking up the basics & haven't really seen much information on deeply compounded statements of this type, most of the examples are pretty much 'if && else' or 'if or' etc.
Any help/elucidation would be much appreciated.