javascript - how to get variable value within function? -


how can return variable value within function?

var mystring = "px"; var mymethod = function(){     if(mystring == 'percent') {         return '%';     } else {         return mystring; // should return 'px'     } $('div').css('width','200'+mymethod()); //not working 

demo

as i'm having problem this:

var scalc = this.classname.split('-')[4];     var fncalc = function(){         if(scalc == 'plus'){             return '+';         } else if(scalc == 'minus'){             return '-';         } else if(scalc == 'multiply'){             return '*';         } else if(scalc == 'divide'){             retutn '/';         } else{             return '+';         } /*bugging me much*/     }; 

i'm not seeing error in console?

you're missing curly brace end function.

var mystring = "px"; var mymethod = function() {     if (mystring == 'percent') {         return '%';     } else {         return mystring; // should return 'px'     } }; $('div').css('width','200'+mymethod()); //not working 

updated jsfiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -