UrbanDweller Posted March 27, 2012 Share Posted March 27, 2012 Hey again Im wanting to call a function inside a function that will check some variables to see if they are in range and return true or false depending on if they are in or out of the required range. Once returned to previous function check the to return for true or false to see whether script should continue. Code layout that i am currently trying, I use global variable in the script but for example i will use local ones. function foo(){ var testMe = 3 var limited = checkLimit(testMe); if(limited == true){ return; } //code continues if limited == false } function checkLimit(e){ if(e == 3){ return true; } // If doesnt equal 3 return false; Thanks guys, I truly love this place makes learning coding enjoyable, if you hit a brick wall you can always come here for advice!! Quote Link to comment https://forums.phpfreaks.com/topic/259782-return-truefalse-from-called-function/ Share on other sites More sharing options...
smerny Posted March 27, 2012 Share Posted March 27, 2012 i'm unsure what your question or issue is Quote Link to comment https://forums.phpfreaks.com/topic/259782-return-truefalse-from-called-function/#findComment-1331448 Share on other sites More sharing options...
UrbanDweller Posted March 27, 2012 Author Share Posted March 27, 2012 Oh well im assuming wen i return true or false it get put inside the limited variable but it deoesnt seem to stop the script if its true. Quote Link to comment https://forums.phpfreaks.com/topic/259782-return-truefalse-from-called-function/#findComment-1331460 Share on other sites More sharing options...
smerny Posted March 27, 2012 Share Posted March 27, 2012 oh, btw you don't need to put (something == true) in a conditional. (something) will do the same. in this case, the limited var is unnecessary as well, you could just put the function right in the conditional statement... i'd change the name of the method to reachedLimit or something like that as well.. so you have if(reachedLimit(testMe)) also this is javascript so it will run without semi-colons at the end of each line, but you should still put them there for good practice. and from your code you posted it would seem that nothing would happen differently based on true or false as there is nothing done in the if block or after Quote Link to comment https://forums.phpfreaks.com/topic/259782-return-truefalse-from-called-function/#findComment-1331464 Share on other sites More sharing options...
UrbanDweller Posted March 27, 2012 Author Share Posted March 27, 2012 Thanks for that, imma put it the other way and see how it goes. That script was just an example of what i want my code to do, I just dont like posting massive amounts of code wen i only need to understand a portion of whats going on. Cause before that return statement returns the function to the function that called that etc but not needed in example imo. Quote Link to comment https://forums.phpfreaks.com/topic/259782-return-truefalse-from-called-function/#findComment-1331466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.