I want to set a variable by running a function and retrieving a value.
This is my code (abbreviated if-checks):
var setToPage = return loopHistory("external");
function loopHistory(scope) {
for (var i = $.mobile.urlHistory.stack.length-2; i>=0; i--) {
if (scope == "internal" ){
if ( some[i] == thing ) || i == 0 ) {
i == 0 ? $temp = "VALUE-ONE" : $temp = "VALUE-TWO"
return $temp;
break;
}
} else if (scope == "external") {
$temp = some[i];
if ( thing == true ) {
return $temp;
break;
}
}
}
}
This does not work.
Question:
How do I declare the value of setToPage by running the function above?
Thanks for help!
returnon the running of the function, and place areturnstatement outside theforloop, right now you're overwriting the$tempvariable on each iteration, and it does'nt seem to be declared anywere, which would probably make it global aswell?