|
||||||
| JavaScript and CSS Extensible Markup Language, Java Script, and CSS questions here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
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>
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.
|
| Sponsored Links |
|
|
|
|||||
|
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!");
}
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 68%