Quote:
Originally Posted by matt1234
I'm just starting out with JavaScript and I'm learning from some tutorials on w3schools.
When I tried opening this in Google Chrome the page was blank. Can anyone explain why?
This is the code:
<html>
<head>
<style type="text/css">
p {font-family:arial narrow;font-size:35px;}
</style>
</head>
<body>
<script type ="text/javascript">
var d = newDate();
var time = d.getHours();
if (time<11)
{
document.write("<p>Good Morning</p>");
}
else if (time>11 && time<15)
{
document.write("<p>Good Afternoon</p>");
}
else
{
document.write("<p>Good Day</p>");
}
</script>
</body>
</html>
<!--Note:
This is an example of an if...else if...else statement.
If the time is less than 11 then a "Good Morning" message is written.
If the time is greater than 11 and less than 15 then a "Good Afternoon" message is written.
If the time is anything else then a "Good Day" message is written.
-->
|
Have you tried putting a space after new? as in "var d = new Date();" That should work. Here is how I did it.
<html>
<head>
<style type="text/css">
p {font-family:arial narrow;font-size:35px;}
</style>
<script type ="text/javascript">
var d = new Date ();
var time = d.getHours();
if (time<11) {
document.write("<p>Good Morning</p>");
}else if (time>11 && time<15) {
document.write("<p>Good Afternoon</p>");
}else {
document.write("<p>Good Day</p>");
}
</script>
</head>
<body>
</body>
</html>