Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > JavaScript and CSS

JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-01-2008, 10:37 AM
Martijn's Avatar   
Martijn Martijn is offline
Newbie
 
Join Date: Jan 2008
Posts: 2
Rep Power: 0
Martijn is on a distinguished road
Default Javascript - Good Day Script

Hello, thanks for viewing. I'm trying to learn javascript and I was reading some tutorials.

right here

They showed an example of an script that shows "Good Morning, Or good day etc..." I didn't find it was quite perfect yet so I tried to edit it an little and ended up with this.

Code:
<script type="text/javascript">
var d = new Date();
var time = d.getHours();
if (time<10) 
{
document.write("Good morning!");
}
else if(time>10 && time<18)
{
document.write("Good Afternoon!");
}
else (time>18 && time<10)
{
document.write("Good Evening!");
</script>
It doesn't seem to work, and I don't know what the bug is. Can anyone help me?
I'm thinking I did something wrong with the "Time > 18 && time <10"
But I'm not sure.
__________________
Duck tape is like the force. It has a light side, a dark side, and it holds the world together.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-03-2008, 12:18 AM
John's Avatar   
John John is online now
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,788
Last Blog:
Passwords
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default

Well first you forgot your closing brace in your last else clause. You never account for the fact that time can equal 10 or 18, and lastly time can never be greater than 18 and less than 10 at the same time, so your last else clause is useless. I'm no javascript expert, but give this a go:

Code:
if (time<=10) 
{
document.write("Good morning!");
}
else if(time>10 && time<18)
{
document.write("Good Afternoon!");
}
else (time>=18)
{
document.write("Good Evening!");
}
That should take care of the logic.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hacking Perl Script falco85 Perl 5 11-12-2007 04:51 PM
JavaScript:Tutorial, Using an External Script TcM Javascript 7 09-11-2007 07:39 AM
(Script) Copy content to clipboard, how? annannienann Visual Basic Programming 0 06-19-2007 05:20 PM


All times are GMT -5. The time now is 06:02 PM.

Contest Stats

Xav ........ 161.68
neerlin ........ 100
satrian ........ 100
delia ........ 100
chili5 ........ 70.08
morefood2001 ........ 42.41
MeTh0Dz|Reb0rn ........ 28.44
RyanTuosto ........ 20
gamiR ........ 19.64
John ........ 14.46

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads