Drycodez Posted August 22, 2011 Share Posted August 22, 2011 function plusplus(){var i=0;if(i==0||i>0){i++}} Y is it dat d var inside the func dont INCREMENT? Link to comment Share on other sites More sharing options...
Drycodez Posted August 22, 2011 Author Share Posted August 22, 2011 var i=0;function plusplus(){if(i==0||i>0){i++}} if i declear the var outside the func, it WORKS! Link to comment Share on other sites More sharing options...
jeffman Posted August 22, 2011 Share Posted August 22, 2011 Right. JavaScript does not support static variables inside functions. When your first function runs, i resets to 0 every time. For this not to happen, one solution is to use a global variable, as your second function does. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 22, 2011 Share Posted August 22, 2011 Let me help...rite. js no haz static vars in funcs. wen yer 1st func runs, i reset 2 0 every time. 4 dis not 2 hpn, 1 sol is 2 use a global var, as yer 2nd func does.Hopefully that's easier to understand for you, Samuel. Link to comment Share on other sites More sharing options...
Drycodez Posted August 22, 2011 Author Share Posted August 22, 2011 Thanks guys, am realy greatfull! Link to comment Share on other sites More sharing options...
jeffman Posted August 23, 2011 Share Posted August 23, 2011 Duuuude . . . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.