CharlieBabbage
Technical User
I'm trying to get text into a web page. The text will vary each day, depending on the current day of the month.
Why does the following only display the text for the 1st day of the month whereas today is the 26th day at the time of posting? When I first wrote this code I did not start with 'if (daynow=1)' but with '(daynow=26)' and it worked fine.
<code>
<SCRIPT LANGUAGE="JavaScript">
datetoday= new Date()
daynow=datetoday.getDate()
if (daynow=1) text="This is the text for the 1st of the month";
else if (daynow=26) text="This is the text for the 26th of the month";
else if (daynow=27) text="This is the text for the 27th of the month";
else if (daynow=28) text="This is the text for the 28th of the month";
document.write(text)
// -->
</script>
</code>
Why does the following only display the text for the 1st day of the month whereas today is the 26th day at the time of posting? When I first wrote this code I did not start with 'if (daynow=1)' but with '(daynow=26)' and it worked fine.
<code>
<SCRIPT LANGUAGE="JavaScript">
datetoday= new Date()
daynow=datetoday.getDate()
if (daynow=1) text="This is the text for the 1st of the month";
else if (daynow=26) text="This is the text for the 26th of the month";
else if (daynow=27) text="This is the text for the 27th of the month";
else if (daynow=28) text="This is the text for the 28th of the month";
document.write(text)
// -->
</script>
</code>