• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if cases and function call

 
Michael Huber
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a quick one here, I'm using a function and I'm basically using it different time for different cases.

function MoveNames(one, two, three, four){

if(one){alert("here at one");}

if(one && two){alert("here at one and two");}

if(three && two){alert("here at three and two");}
}

problem is when I call the function with different parameters it gets caught in the case that its not supposed to be in.

Example:
MoveNames('one','two', '', '');
//this alerts "here at one" followed by "here at one and two"


anyway around this???
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the problem. You are testing for the existence of the parameters and it's giving you the expected results.

Perhaps it'd be best if you tell us what exactly you are trying to do, and to use the UBB code tags to make your code more presentable.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is true in both cases, hence why you are seeing two alerts.

Use "else if" statements....and change the order of the checks.

Those two hints should help you out.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic