It looks like you're new here. If you want to get involved, click one of these buttons!
<script>
function displayDate() {
var months = new Array(12);
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="April";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="August";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December";
var days = new Array(7);
days[0]="Sunday";
days[1]="Monday";
days[2]="Tuesday";
days[3]="Wednesday";
days[4]="Thursday";
days[5]="Friday";
days[6]="Saturday";
var thisDate=new Date();
var interval = 2; //Setting the interval as a variable to show its applicability
var curDay=thisDate.getDay()-0+interval;
var curMonth=thisDate.getMonth();
var curDate=thisDate.getDate()-0+interval;
var curYear=thisDate.getFullYear();
document.write(""+days[curDay]+", "+months[curMonth]+" "+curDate+", "+curYear);
}
</script>
I thought replacing
document.write(""+days[curDay]+", "+months[curMonth]+" "+curDate+", "+curYear);
with
document.getElementById('foo').innerHTML = ""+days[curDay]+", "+months[curMonth]+" "+curDate+", "+curYear;
would do the trick, and adding the div 'foo' to the passage I want it to appear on, but unfortunately nothing is showing up.
Comments
Additionally, I feel like you're not using Arrays to their full potential either. You should instead write "months" and "days" like this: Now, as for making this usable within Twine... consider putting all of that into a function, like so: Then, you can use it in a macro like so:
Good call on the dates. I thought about that in an earlier attempt...but obviously promptly forgot to consider it in further attempts when that one didn't work!
And yes, your method for months and days is much better. Thank you for cleaning that up!!
The line flagged issues in Dreamweaver, (even though it didn't tell me why!) and building with this code caused the whole thing to say
"Sorry to interrupt, but this page's code has got itself in a mess (SyntaxError: missing ) after argument list).
You may be able to continue playing, but some parts may not work properly."
So I added ) to make it which made it much happier.
Date then printed fine, except for the year which is apparently 114.
So I changed to And it's all good!
Had a colleague come in and try and help me work out why it wasn't working to begin with; he picked up the ) ...I just didn't press space/enter to parse it and remove the error message, so we thought it hadn't worked when we had actually fixed it by adding the ). We ended up with this: which produces the right result but has an extra line of which isn't needed.
Thank you very much for your help!!