Forum Moderators: open

Message Too Old, No Replies

Total Newbie needs help

need help creating a script

         

reddfoxx

1:20 am on Jun 1, 2004 (gmt 0)



Hi everyone,
I am totally new to JavaScript. I am following along in a book and trying to get the concepts down, but have been stuck on one of the examples. I am supposed to create an internal script that accomplishes the following tasks:

A. Create a global variable named age. Initialize the variable to your age.
B. Create a global variable named YearBorn.
C. Create a global variable named yearSSN.
D. Create a function named CalculateBorn that will compute the year you were born based on your current age.
E. Create a function named CalculateSSN that will compute the year you will start to draw social security based on age 65.
F. Display the following output on three separate lines in the following order.
(a) Current age
(b) Year born
(c) Year social security will start.

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

MichaelBluejay

1:54 am on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You've come to the right place. But first let me ask you to title your threads with something more descriptive. WebmasterWorld is unusual in that it gives you TWO subject lines, but you didn't really use either of them. Of *course* you need help with a script. That's why you're posting to this forum. But what is the nature of the problem? Your subject lines don't say. For this issue I'd suggest something like, "How to calculate birth year based on user's age?"

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.