View Full Version : cant get it to work
ecntrc
06-29-2003, 02:51 AM
ok..here is what i have right..i have a big feeling that it is totally..off..
<html>
<head><title>JaVa</title></head>
<body bgcolor="black">
<script language="javascript">
prompt ();
if (hours>=06&&hours<=09) //MESSAGE FOR MORNING
document.write('<b>..Break Fast is Served..</b>')
else if (11&&hours<==1) //MESSAGE FOR NOON
document.write('<b>Time For Lunch!</b>')
else if (hours>=18&&hours<=20) //MESSAGE FOR EVENING (6pm-8pm)
document.write('<b>Time for Dinner!</b>')
else if (hours>=21&&hours<=11) //MESSAGE FOR NIGHT (9pm-11pm)
document.write('<b>GO HOME!</b>')
</script>
<p><fontface="arial"><h2>does it work uncle T?</h2></font></p>
</body>
</html>
there is another thing that i needed to add to that, which was if they enter any other hour when they are promt for the question, and they put any other hour, such as 4pm then it will also tell them to go home...uggghh...please dont laugh i know its probably way off but i tried. thanks..any help? :eek:
SDP2006
06-29-2003, 03:36 AM
First of all, you havent called the date object. So when you have "(hours>=06&&hours<=09)" the script has no idea what to do because you havent called the date object. Secondly, what are you prompting? What you have now is just going to bring up a prompt box. Im not good enough to fix it, maybe someone else can.
Good Luck
Skyzyx
06-29-2003, 03:46 AM
First of all, Read the posting guidelines (http://www.codingforums.com/showthread.php?s=&threadid=2090), especially #1 and #2.
Next, I'm not sure what in the world you were trying to do with the prompt, but this will write a message depending on the time of day on the user's computer.
<html>
<head>
<title>Time-of-day messages</title>
<style type="text/css">
h2 {
font-family:Arial;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
function timeOfDay()
{
var rightNow=new Date();
var hours=rightNow.getHours()+1;
if (hours>5 && hours<9) document.write('Breakfast is served.'); // Between 6:00am and 8:59am
else if (hours>10 && hours<13) document.write('Time for lunch.'); // Between 11:00am and 12:59pm
else if (hours>17 && hours<20) document.write('Time for dinner.'); // Between 6:00pm and 7:59pm
else if (hours>20 && hours<23) document.write('Go home.'); // Between 9:00pm and 10:59pm
}
//-->
</script>
</head>
<body>
<h2>Does it work uncle T?</h2>
<script language="JavaScript" type="text/javascript">
<!--
timeOfDay();
//-->
</script>
</body>
</html>
ecntrc
06-29-2003, 03:57 AM
ok, now i am half way there...thanks to you...my rescuer! what im trying to do is, i want to ask the user what time it is, then when they type in the hour then a message will pop up, depending on the time, ex:7am message:breakfast is served.
now im going to try and put in the prompt code, but im not sure how to set it up to work together..?
<html>
<head>
<title>Time-of-day messages</title>
<style type="text/css">
h2 {
font-family:Arial;
}
</style>
<script language="JavaScript" type="text/javascript">
prompt(); what time is it?
<!--
function timeOfDay()
{
var rightNow=new Date();
var hours=rightNow.getHours()+1;
if (hours>5 && hours<9) document.write('Breakfast is served.'); // Between 6:00am and 9:00am
else if (hours>10 && hours<13) document.write('Time for lunch.'); // Between 11:00am and 1:00pm
else if (hours>17 && hours<20) document.write('Time for dinner.'); // Between 5:00pm and 8:00pm
else if (hours>20 && hours<23) document.write('Go home.'); // All other hours
}
//-->
</script>
</head>
<body>
<h2><center><b>does it work uncle T?</b></center></h2>
<script language="JavaScript" type="text/javascript">
<!--
timeOfDay();
//-->
</script>
</body>
</html>
?? ahh dosent work
please help if can, also, i did read the posting recs.<h5>
Skyzyx
06-29-2003, 04:24 AM
You want the user to punch in the hour? In other words, you don't want the script to read the time on the user's computer. Okay. Completely different scenario...
<html>
<head>
<title>Time-of-day messages</title>
<style type="text/css">
h2 {
font-family:Arial;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
function timeOfDay()
{
var hours=parseInt(prompt('Enter the number of the hour that it currently is in military time (i.e. 18:00 instead of 6:00pm)', ''));
if (hours>5 && hours<9) document.write('Breakfast is served.'); // Between 6:00am and 8:59am
else if (hours>10 && hours<13) document.write('Time for lunch.'); // Between 11:00am and 12:59pm
else if (hours>17 && hours<20) document.write('Time for dinner.'); // Between 6:00pm and 7:59pm
else if (hours>20 && hours<23) document.write('Go home.'); // Between 9:00pm and 10:59pm
}
//-->
</script>
</head>
<body>
<h2>Does it work uncle T?</h2>
<script language="JavaScript" type="text/javascript">
<!--
timeOfDay();
//-->
</script>
</body>
</html>
ecntrc
06-29-2003, 05:37 AM
well..ok..i tried it, put some coding in it and it didnt work. i took out what i put in and tried to change the times to am and pm, didnt work. also, i needed the prompt first, asking what time it is right, they will put in waht time it is, and according to the coding we put it pops up a message saying..breakfast is served.
do i place the script tag for the prompt in the same as the hours codes? ahhhhhhhhhhh im sorry if im confusing..:mad:
Skyzyx
06-29-2003, 06:09 AM
This script requires you to use military time. 18:00 instead of 6:00pm. You never said that you wanted it to popup before. You need to specify.
Remember that 9:00am will not say "Breakfast is served." However, 8:59am will. You need to read the comments to make sure you understand. Things like "I don't know, it just doesn't work" don't help me fix your problem any easier.
<html>
<head>
<title>Time-of-day messages</title>
<style type="text/css">
h2 {
font-family:Arial;
}
</style>
<script language="JavaScript" type="text/javascript">
<!--
function timeOfDay()
{
var hours=parseInt(prompt('Enter the number of the hour that it currently is in military time (i.e. 18:00 instead of 6:00pm)', ''));
if (hours>5 && hours<9) alert('Breakfast is served.'); // Between 6:00am and 8:59am
else if (hours>10 && hours<13) alert('Time for lunch.'); // Between 11:00am and 12:59pm
else if (hours>17 && hours<20) alert('Time for dinner.'); // Between 6:00pm and 7:59pm
else if (hours>20 && hours<23) alert('Go home.'); // Between 9:00pm and 10:59pm
}
//-->
</script>
</head>
<body>
<h2>Does it work uncle T?</h2>
<script language="JavaScript" type="text/javascript">
<!--
timeOfDay();
//-->
</script>
</body>
</html>
ecntrc
06-29-2003, 06:48 AM
your the greatest..the code worked out similiar to the way i wanted it to. but its good enough. thanks a bunch for your help. ;0):thumbsup:
i appreciate it alot homie ;oP:thumbsup:
ecntrc
06-29-2003, 07:23 PM
how would i be able to get it to say "go home" to any other hours besides the breakfast, lunch & dinner times? i tried somethings but its not working. other than that it works. i jus need it to say go home to anyother time the user puts other than the breakfast, lunch & dinner. any help..please?:rolleyes:
SDP2006
06-29-2003, 09:20 PM
Are you doing this for a project in school or a project in college?
What is the purpose of this, anyways?
ecntrc
06-29-2003, 10:27 PM
college...the text books we have suck. this is like intro to javascript to me. html, i have no problem at all with. but this is another story. its not really a project its an assignment. he says we should be able to do it in 15 minutes. but not me. im having trouble. if you dont want to continue to help i understand.
Skyzyx
06-30-2003, 04:47 PM
Change this:
else if (hours>20 && hours<23) alert('Go home.'); // Between 9:00pm and 10:59pm
... to this...
else alert('Go home.'); // Any other time
ecntrc
06-30-2003, 06:08 PM
i tried to do the, between for each hour that didnt have a message except Go Home, but you have provided me with an easier code, and im so happy! it works! thank you so much! ;o):thumbsup:
ecntrc
06-30-2003, 08:48 PM
im like really happy, dont think im like psycho or anything. i appreciate the help that i have recieved from you guys. my code works. made some changes all the better it works!!! thanks again!!!:p
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.