/    Sign up×
Community /Pin to ProfileBookmark

Need help with JavaScript Problem!

I can’t figure out why my code is not working. Can someone please tell me what I am doing wrong?

I am trying to create a script that displays the current date and time and displays a welcome message depending on the time of day.

Thanks!

<head>
<title>Welcome</title>
<meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ />
<link rel=”stylesheet” href=”js_styles.css” type=”text/css” />

</head>
<body>
<h1>Welcome to my Web Page</h1>
<script type=”text/javascript”>
/* <![CDATA[ */
var dateObject = new Date();
var greeting = “”;
var curTime = “”;
var minuteValue = dateObject.getMinutes();
Var hourValue = dateObject.getHours();
if (minuteValue < 10)
minuteValue = “0” + minuteValue;
if (hourValue < 12) {
greeting = “<p>Good Morning! ”
curTime = hourValue + “:” + minuteValue + ” AM”;
}
else if (hourValue == 12) {
greeting = “<p>Good Afternoon! “;
curTime = hourValue + “:” + minuteValue + ” PM”;
}
else if (hourValue < 17) {
greeting = “<p> Good Afternoon!”
curTime = (hourValue-12) + “:” + minuteValue + ” PM”
}
else {
greeting = “<p>Good evening! ”
curTime = (hourValue-12) + “:” + minuteValue + ” PM”
}
var dayArray = new Array(“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”);
var monthArray = new Array(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”);
var day = dateObject.getDay();
var month = dateObject.getMonth();
document.write(“<p>”+ greeting + “It is ” + curTime + ” on ” + dayArray[day] + “, ” + monthArray[month] + ” ” + dateObject.getDate() + “, ” + dateObject.getFullYear() + “.</p>”);
/* ]]> */
</script>
</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleNov 14.2008 — Var hourValue = dateObject.getHours();

should not have a capital "V"
Copy linkTweet thisAlerts:
@andy21aaNov 14.2008 — Replace the capital 'V' in var with a small 'v'

Var hourValue = dateObject.getHours();
Copy linkTweet thisAlerts:
@wahbooauthorNov 14.2008 — Thank you! I can't believe it was something that simple. :eek:
×

Success!

Help @wahboo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...