Given the following skeleton HTML file, write the necessary JavaScript code to decide whether it is "Caturday" (Saturday) when the "Is it Caturday?" button is clicked.
You should inject "YES" or "NO" into the #answer paragraph depending
on whether the current day of the week is Caturday. You should also change the class
of the body
tag to .yes
or .no
accordingly.
You will find the Javascript Date class very helpful.
Here's a working solution for you to try out. (Don't peek at the code!)
<p>
<button id="button" onclick="caturday();">Is it Caturday?</button>
</p>
function caturday() {
var today = new Date();
// var today = new Date("April 23, 2011 01:23:45");
var text = "NO";
if (today.getDay() == 6) {
text = "YES";
}
document.getElementById("answer").innerHTML = text;
document.body.className = text.toLowerCase();
}