/    Sign up×
Community /Pin to ProfileBookmark

please, I am missing something in this little

java script

everthing is working expect what I want to do below:

I am trying to make it so that the little message box displays “why didnt you enter your name” if the user clicks CANCEL or simply clicks OK without putting in any data.

Here is the short script below, everthing else works but this little thing I am trying to do

<!testingscript language=”JavaScript”testing>
<!–
var name=prompt(“Could you please enter your first name here ?”,””);
if (name!=null&&name!=”How come you didnt put your name? Now please, click the refresh button on you screen above and try again, but this time enter your name ?”)
var today = new Date ()
var hrs = today.getHours();
document.writeln(“<b><font size=4 face=’Comic Sans MS’>”);
document.writeln(“<b>”);

if (hrs <= 12)
document.write(“Good Morning “+name+’!’);
else if (hrs <= 18)
document.write(“Good Afternoon “+name+’!’);
else
document.write(“Good Evening “+name+’!’); document.writeln(“<br>”);

// –>
<!/scripttesting>

I am on standby for an example script please, can someone give me an example of what I need to write out ?

Thank you so much……………….

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@peiguoFeb 25.2004 — Do something like this:


<HTML>

<HEAD>

<script language="JavaScript"testing>

var name=prompt("Could you please enter your first name here ","");

if ((name==null) || (name == "")) {

alert("How come you didnt put your name? Now please, click the refresh button on you screen above and try again, but this time enter your name ")

} else {

var today = new Date ()

var hrs = today.getHours();

document.writeln("<b><font size=4 face='Comic Sans MS'>");

document.writeln("<b>");

if (hrs <= 12)
document.write("Good Morning "+name+'!');
else if (hrs <= 18)
document.write("Good Afternoon "+name+'!');
else
document.write("Good Evening "+name+'!'); document.writeln("<br>");

}

</script>

</HEAD>

<BODY>

</BODY>

</HTML>
×

Success!

Help @chessman 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 5.10,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...