• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

if cases and function call

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.

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

anyway around this???
Posts: 67418
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
Posts: 15385
  • 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.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic