/    Sign up×
Community /Pin to ProfileBookmark

Trying to use images as responses to an if statment

I am just getting into Java Script because I have to…lol, and am totally lost..
We are trying to use an if statement (function??) tied to the time of day…and want the response to be a different greeting for each different condition and also have a different image tied to the greeting.

The responses are not a problem… but I do not know how to code the images so they will tie to the responses… (only know enough html to get myself in trouble..but do know the basic tags and img src tags).

Here is the code with out the images..


________________________________________________

<script language=”JavaScript”>
<!– hide script from old browsers
// Modified by CoffeeCup Software
function process(){}

today = new Date()

if(today.getMinutes() < 10) {
pad = “0”}
else
pad = “”;
document.write(“<center><FONT SIZE=4 color=yellow></FONT></center>”)

if((today.getHours() < 12) && (today.getHours() >= 6))
{ document.write(“<center><FONT SIZE=4 color=blue>Good Morning</FONT></center>”)}

if((today.getHours() >= 12) && (today.getHours() < 18))
{ document.write(“<center><FONT SIZE=4 color=red>Good Afternoon</FONT></center>”)}

if((today.getHours() >= 18) && (today.getHours() <= 23))
{ document.write(“<center><FONT SIZE=4 color=white>Good Evening</FONT></center>”)}

if((today.getHours() >= 0) && (today.getHours() < 4))
{ document.write(“<center><FONT SIZE=4 color=purple>You’re up late today.</FONT></center>”)}

if((today.getHours() >= 4) && (today.getHours() <= 6))
{ document.write(“<center><FONT SIZE=4 color=yellow>Wow! You are up early!!</FONT></center>”)}

document.write(“<center><FONT SIZE=3 color=blue>Time: “,today.getHours(),”:”,pad,today.getMinutes())

document.write(” Date: “,today.getMonth()+1,”/”,today.getDate(),”/”,today.getYear(),”<br></font></center>”);
// end hiding contents –>
</script>


______________________________

Any help would be appreciated … our images are on a website and have the normal addresses for the urls…. so we just need to know how to write it so it will appear with the different greetings…

Thanks in advance for any help…
Having a blast learning and reading up in manuals… but can’t seem to find an answer for this that we can understand.

THanks a bunch,
Katie

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 27.2003 — Though I am not a big fan of document.write...you adding an image to this is fairly simple

change this line

document.write("<center><FONT SIZE=4 color=blue>Good Morning</FONT></center>")

to this

document.write("<center><FONT SIZE=4 color=blue>Good Morning</FONT><br<img src='someImage.gif'/></center>")
Copy linkTweet thisAlerts:
@katieauthorJun 28.2003 — ? ?

Thank you very much, I shall try it this weekend and let you know how it works!

Katie
×

Success!

Help @katie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...