Jump to content

return true/false from called function?


UrbanDweller

Recommended Posts

Hey again  :P

 

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!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.