/    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

1 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyNov 14.2008 — Line 16 starts with an invalid capital letter:

Var hourValue = dateObject.getHours();

Always check for error messages being generated in your browser. I found the error by pasting your code into a new document on my desktop and loading it up in IE7. I was immediately greeted by an error message dialog pointing to that line. If your browser doesn't display an error message dialog right away, this does not mean there are no errors.

On the left side of the status bar, IE will display a small yellow triangle with a black exclamation mark inside of it. Double-click that to get the error message dialog. Or, go into Tools / Internet Options / Advanced and check the option to display error notifications.

If you have installed the web developer tools in the current version of FF, then FF will display a red circle with a white exclamation mark inside of it on the web developer toolbar. Click that to get the error console -- or Ctrl-Shift-J.
×

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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...