jackhammer013 February 2016

Min and Maxium Age Comparison jQuery

Hi I'm new to PHP and I need to make a validation that if the customer age bracket doesn't satisfy the filter then I will disable the question lets say

Customer Age Bracket = 40 -44
Question Age Bracket = 18-75

So basically the customer is still in the bracket and should be allowed to take the question. Let's say

minQuesAge = 18;
maxQuesAge = 75;

minCusAge = 40;
maxCusAge = 44;

I have

if(parseInt(minCusAge) >= parseInt(minQuesAge) && parseInt(maxCusAge) <= parseInt(maxQuesAge))
{
     console.log("Need to disable");                    
}

Why is that I still got Need to disable? Is my Condition correct?

Answers


Barmar February 2016

Your conditions are for when the age is valid, you need to invert it to get the condition for disabling. You can invert a condition with the ! operator.

if(!(parseInt(minCusAge) >= parseInt(minQuesAge) && parseInt(maxCusAge) <= parseInt(maxQuesAge)))
{
     console.log("Need to disable");                    
}

You can also use deMorgan's Law to invert the parts of the condition.

if(parseInt(minCusAge) < parseInt(minQuesAge) || parseInt(maxCusAge) > parseInt(maxQuesAge))
{
     console.log("Need to disable");                    
}

Post Status

Asked in February 2016
Viewed 1,239 times
Voted 12
Answered 1 times

Search




Leave an answer