Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectAre there any Javascript experts here? Reply to this message
Posted bypostamessage
Posted on09/06/06 09:11 PM



I'm trying to learn to hand code javascript based on tutorals and page sources and nowhere as easy as html. What I want to do is have a heading read different text based on the time of day and I'm about to give up due to pure fustration. I have no idea how to start my code since everything I've tried doesn't work. Also can you check my "if command" code below for errors? It should also give you an idea of what I'm trying to do.

if(hours<=5 && >=11){
document.write("Good Morning!")
}

if(hours<=12 && >=16) {
document.write("Good Afternoon!")
}

Photobucket - Video and Image Hosting


SubjectErrors new Reply to this message
Posted bySnowball 2
Posted on09/06/06 09:33 PM



You've got partially complete boolean expressions.


if(hours<=5 && hours >=11)
{
document.write("Good Morning!")
}

if(hours<=12 && hours >=16)
{
document.write("Good Afternoon!")
}


Each expression is evaluated on its own so you have to write them both completely. Also you have impossible conditions. The &&(AND) should probably be ||(OR). Both expressions have to be true for that code to execute. You can't have a number that's less than 12 and greater than 16 at the same time. I'm not sure what you're assuming given the numbers in your code but if you were to write this as 0 to 11 as AM and 12 to 23 as PM then it would look like this.


if(hours >= 0 || hours <= 11)
{
document.write("AM MOTHERFUCKA!")
}

if(hours >= 12 || hours <=23)
{
document.write("PM BITCH TITS!")
}


And this might have been what you were aiming for (again assuming 0-23 hours).


if(hours >= 0 || hours <= 5)
{
document.write("You're on a coke binge if you're reading this!");
}

if(hours >= 5 || hours <=11)
{
document.write("Good morning, ho!")
}


if(hours >= 12 || hours <= 17)
{
document.write("Good afternoon, cunt lips!")
}


if(hours >= 18 || hours <= 23)
{
document.write("Good evening!")
}


pixel-eight.com



Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode