Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntex problem

Status
Not open for further replies.

greatfalls

Technical User
Jul 1, 2001
21
0
0
CA
Hi,
How would I fix the below.
I have a global variable at the top of my scripts and it gets used down below in some functions.
<script language=&quot;JavaScript&quot;>
RetirementAge = 60;
</script>

But retirement age is 60 or greater, how would I declare that?

a piece of one of the fucntions where it is used is (CurrentAge <= RetirementAge )

Thanks for any helpl
 
I'm sorry, I don't understand, what do you want it to do? You can declare it to be any value you like, just set it to a different number? Aren't you coping with the fact that retirement age is >= 60 by using the code you already have?
 
I am declaring this in the beginning of my scripts to use down below.

<script language=&quot;JavaScript&quot;>
RetirementAge = 60;
</script>

But what I want to declare is RetirementAge >= 60;

So when I change it I get an error &quot;RetirementAge is undefined

So I guess I have to say something like RetirementAge = 60 or greater;

Thanks for your response


 
Well, the = sign does not actually mean equals in this context. Here it is an assignment operator. You cannot do what you are trying to do, you have to code it into the rest of the script. You just need a simple checking funtion even

function isRetired(age){
var thisPersonIsOver60 = false;
thisPersonIsOver60 =(age >= RetirementAge)?true:false;
return thisPersonIsOver60;
}


returns true if the person is over 60. So you just call this function, and pass the age you want to compare, I presume this will come from a form. So instead of

if(CurrentAge <= RetirementAge ){
//this person is not retired
}

you could have

if(!isRetired(CurrentAge)){
// This person is not retired
}


which will return the same result. You have to do some comparison.Note have used the ! operator because the function isRetired returns true if they are retired, but here we wanted true if they aren't.
It says &quot;If not retired&quot;.
 
Bangers,
Thanks for a great explanation!!! Greatfalls


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top