Current location: Hot Scripts Forums » General Web Coding » JavaScript » Beginner JavaScript need help!


Beginner JavaScript need help!

Reply
  #1 (permalink)  
Old 08-27-11, 07:10 AM
matt1234 matt1234 is offline
New Member
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Beginner JavaScript need help!

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.
-->

Last edited by matt1234; 08-27-11 at 07:13 AM.
Reply With Quote
  #2 (permalink)  
Old 09-23-11, 09:02 PM
mosquitomonk mosquitomonk is offline
New Member
 
Join Date: Sep 2011
Location: USA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by matt1234 View Post
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>
Reply With Quote
  #3 (permalink)  
Old 10-06-11, 12:23 PM
tutorholic tutorholic is offline
New Member
 
Join Date: Oct 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mosquitomonk is right. try putting a space between new and Date
Reply With Quote
Reply

Bookmarks

Tags
beginner, javascript, need help


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
beginner javascript programming learner JavaScript 1 10-02-10 11:14 AM
Senior JavaScript Developer - Full Time - Permanent - London AJAX, CSS, JSONP Chris Peacock Job Offers & Assistance 0 01-19-10 12:28 PM
glorified disjointed rollovers with javascript asinausk JavaScript 0 09-01-09 09:50 PM
Reaaly stuck about javascript over frames muratisik JavaScript 1 12-14-03 11:58 AM


All times are GMT -5. The time now is 02:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.