if arguments in JavaScript

  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 131

Post 3+ Months Ago

How would I get an if statement to run an argument with "||" and "&&"?

example:

if (a<1 || b<1 || c<1 && x>1)

I need to know how to make the function execute if one of three arguments are true, AND another argument is true. Is there any way to make that work?
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Umm .... Are you needing to have x to be greater than one no matter what a,b and c are? kind of like this? http://jsfiddle.net/rjsL9/
  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 131

Post 3+ Months Ago

The arguments/variables are just random. But from the link, it looks like you just put the "or" arguments in parenthesis and the "and" argument outside of it. I'm surprised I didn't think to try that. Thanks very much. :)


In case anyone else has this problem the solution is:

if ((var<1 || var<1 || var<1) && var==4)

FYI the values and comparison operators are just random examples to express the point.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 31 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.