I want to house a variable in a function. This variable will change state depending on user interaction. For example:
function plan_state(current){
if (current != ''){
state = current;
}
else {
return state;
}
}
When the document loads I call plan_state('me')
, and when certain things happen I may call plan_state('loved')
. The problem occurs when I run a function and want to check the current state:
alert(plan_state());
I get undefined
back, but the value should be 'me' as I previously set this value on document load.
What am I doing wrong?