Date Code


#1

What's wrong with the code? The text in "document.write" is not showing!

<!doctype html>
<html lang="en-US">
<title>Date/Time</title>
<head>
<style type="text/css">
body {
color: black;
background-color: white;
zoom: 400%;
}
center {
font-family: "Courier New";
font-size: xx-large;
}
</style>
</head><body>
<center><b><p>
<script>
var current = new Date()
var day = current.getDate()
var month = current.getMonth()
var year = current.getFullYear()
var printedMonth
if (month == 1){
printedMonth = "January"
}
if (month == 2{
printedMonth = "February"
}
if (month == 3){
printedMonth = "March"
}
if (month == 4){
printedMonth = "April"
}
if (month == 5){
printedMonth = "May"
}
if (month == 6){
printedMonth = "June"
}
if (month == 7){
printedMonth = "July"
}
if (month == 8){
printedMonth = "August"
}
if (month == 9){
printedMonth = "September"
}
if (month == 10){
printedMonth = "October"
}
if (month == 11){
printedMonth = "November"
}
if (month == 12){
printedMonth = "December"
}
document.write(printedMonth + " " + day + ", " + year)
</script>
</p></b></center>
</body>
</html>

#2

Is this related to a lesson? If not, we will need move it to the Corner Bar for open discussion and advice. It should not be in a lesson category if not directly related to the exercises (or in the this case, the track, itself).


#3

This will shorten the code and make it a little more dynamic...

var months = [
    "January", "February", "March", "April", 
    "May", "June", "July", "August", "September", 
    "October", "November", "December"
];
var printedMonth;
printedMonth = months[month-1];