Forum Moderators: open

Message Too Old, No Replies

adding a function to day of week

brain gone to mud... @ 82

         

Oddjob41

12:13 pm on Mar 6, 2023 (gmt 0)

5+ Year Member Top Contributors Of The Month



I've gotten this far, after searching:
var month = new Date().getMonth() + 1; // Month of year, 1 to 12
let date = new Date();
date.getDate();
let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
days.forEach((day,index)=> {
if(index == new Date().getDay()) { console.log("Today is "+day) }
}
)
Instead of
console.log("Today is "+day)
am trying to do this:
if today is Sunday doThis();
if it's Monday, doThat(),
if it's Friday, doThese()... etc --different function for each day.
Would appreciate any pointers.
Cheers.

lucy24

5:28 pm on Mar 6, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sounds like a textbook case of

... uh, oops, javascript doesn't call it SELECT/CASE does it ...

switch (day)
{
case blahblah:
  do stuff;
case otherblah:
  do other stuff;
case thirdblah:
  do still other stuff;
}
and so on.

Oddjob41

8:50 am on Mar 7, 2023 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanx Lucy
mud clearing...