Hello everyone! I am 100% completely new to JavaScript. I am trying to complete some JavaScript for an intro JavaScript class.
In a nutshell: I am displaying the date my fiance and I got engaged, am utilizing a button to reveal our wedding date, and would like to display a message if the current date is past the set wedding date. [B]The problem I am having is with displaying a message if the current date is past the wedding date.
I tested it out by changing the set wedding date to be in the past (I just changed the year to be 2009 temporarily) but the message appeared on the page. I tried playing around with it more, searching for more info using if statements for dates, so on and so forth. I am just coding myself in circles at this point and feel totally lost (hence my username!). What am I doing wrong? How do I make this work? ?
Unfortunately I do not have a test page as I do not have a website yet. Hoping the code is simple enough that posting it below will suffice. Thanks in advance for any help!
[code]
<!DOCTYPE HTML>
<head>
<meta charset=”utf-8″>
<title>Wedding Date Reveal</title>
<script>
<!–
function weddingDate()
{
var wd = new Date();
wd.setFullYear(2013,0,5);
var reveal = document.getElementById(“weddingdate_reveal”);
reveal.innerHTML=wd;
}
function afterWedding()
{
var aw = new Date();
if (aw>wd) {
var afterWedding = document.getElementById(“after_wedding”);write(“Sorry, our wedding date has passed! It was on January 5, 2013.”);
afterWedding.innerHTML=aw;
}
}
//–>
</script>
</head>
<body>
<p>We got engaged on
<script type=”application/javascript”>
var ed = new Date();
ed.setFullYear(2010,10,24);
document.write(ed)
</script>
</p>
<p>We are getting married on … <br />
<button onclick=”weddingDate()”>Click for the date!</button> </p>
<p id=”weddingdate_reveal”></p>
<p id=”after_wedding”></p>
</body>
</html>