How are ya? By the way, if you don't want to go through the whole input name prompt, confirm box thing again, don't press refresh. Every time you press refresh or come back to this page from somewhere else, you will encounter these things.
Sorry...
I'm just beginning to learn JavaScript. And I'm not really all that good, yet. I'm told that if you only want a user to see these things once, and only once, you have to use a cookie. But I haven't got that far yet in my learnings... so, this is just the way it is for now. When I learn to do it better, I will.
But...
Ya want to know how I did it? Well, I actually did three things. The first thing you encountered, was a prompt, asking you to input a name. If you did, you have found that I am calling you by that name. If you didn't, I'm calling you "Stranger" right now.
The second thing you saw was a confirm box, asking whether or not you wanted to proceed to this page. If you pressed OK, you came here, if you pressed Cancel, you went back to the main page.
The last thing on this page is a countdown - counting down the days until a certain event.
PS. Page 2 has the code for MouseOvers, which are essentially 2 images that get swapped if you put your mouse over them or take it off them.
If there's anything on these pages that you really just don't get, Email Me, but at least give it a shot first.
var user=prompt('Please enter your name.','');
if ((user=='')||(user==null)||(user=='undefined'))
{
user="Stranger"
}
//STOP HIDING ME-->
document.write("Hey, " +user+ "!")
//STOP HIDING ME-->The firt part of the code is basically saying:
Create a variable called 'user'. Make the value of 'user' equal to whatever the user inputs in a prompt box which will be called up when the page is opened, saying "Please enter your name," and having nothing pre-typed in the box. If the user doesn't type anything, or what the user typed cannot be interpreted by the computer, then simply assign 'user' the value of 'Stranger'.
The part of the code in the body is basically saying:
Write "Hey, " and then whatever value 'user' has been assigned (ie. the user's name), then an exclamation mark.
function askIf() {if (!confirm
("Are you sure you want to see the JavaScript Page?
If you're not interested in JavaScript, there's not
much for you here..."))
history.go(-1);return " "}
document.writeln(askIf())
//STOP HIDING ME-->Well, the first part,
<script language = "JavaScript">
<!--HIDE ME
and the last,
//STOP HIDING ME-->
</script>
are the basic opening and closing statements in JavaScript.
The rest of the code is basically saying:
Create a function name 'askIf' which will pull up a confirm box saying "Are you sure... blah, blah, blah..." If they cancel, send them back 1, (in relation to their internet history).
The last bit,
;return " "}
document.writeln(askIf())
is saying:
Once this code has been completed, return a value of " ", or nothing, for the function 'askIf()'. Then write the value of askIf() [which we've set at nothing] on to the document, a final line which is necessary to make the code work.
var date = new Date("June 3, 2004");
var description = "my birthday!";
var now = new Date();
var diff = date.getTime() - now.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
document.write("<center><h3>")
if (days > 1) {
document.write(days+1 + " days until " + description);
}
else if (days == 1) {
document.write("Only two days until " + description);
}
else if (days == 0) {
document.write("Tomorrow is " + description);
}
else {
document.write("Yeah! Yeah! It's my birthday!");
}
document.write("</h3></center>");
//STOP HIDING ME-->This code is basically saying:
Create a whole bunch of variables (what each of them is, is fairly self-explanatory). Then do some 'Math' to figure out the difference (in days) between the specified date and the present date. Depending on how many days are left until the date (or if the date has already arrived), the message changes from "There are " so many "days until" this event, to "Only two days until " this event, and so on.
PS: The code for the countdown on this page may or may not count down to my birthday as I change it to a countdown of something else, after my birthday. Regardless, the code is the same - what it counts down to is up to you!