Forum Moderators: open
I know it must seem basic to most, but as a beginner I am lost. I have no problem with HTML and want to expand into JavaScript but can't seem to get past this point in the book. I would appreciate some help if anyone is willing. I don't even need the whole script, but would really be able to use some examples that might be able to work as a reference to create this script.
Thanks!
reddfoxx
Okay, on to your question. I'll write *some* of your code but not the whole thing.
<SCRIPT language=JavaScript>
age = 29;
calculatedYearBorn = calculateBorn(age) // Call the calculateBorn function
alert(calculatedYearBorn); // Give the answer to the user
function calculateBorn(age) {
now = new Date();
currentYear = now.getFullYear;
return currentYear - age;
}
---------
Variables rarely need to truly be global. If you really need a global variable you use <window.age> instead of <age>.
For beginning JavaScript, I recommend the book _JavaScript: The Definitiev Guide_ published by O'Reilly.