# how to get if a negative number is in a range

i have a number that will sometimes fall below 0 (negative) how do i check for that give like this please
``````// \$percent_color=getColor(-0.4);
function getColor(\$n){

// Return default (black) for all other numbers
if(\$n==0) return "black";

// Is number between 1 and 5?
if(\$n>=0.1 && \$n<=10) return "green";

// Is number between 6 and 50?
if(\$n>=11 && \$n<=20) return "orange";

// Is number greater than 50
if(\$n>21) return "red";

// negitive lookup

// Is number between 1 and 5?
if(\$n>=-0.1 && \$n<=-10) return "green";

// Is number between 6 and 50?
if(\$n>=-11 && \$n<=-20) return "orange";

// Is number greater than 50
if(\$n>-21) return "red";

}
``````
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
This bit looks wrong, you have the logic the wrong way around. I have corrected

// Is number between 1 and 5?
if(\$n<0 && \$n>=-10) return "green";

// Is number between 6 and 50?
if(\$n<-11 && \$n>=-20) return "orange";

// Is number greater than 50
if(\$n<-20) return "red";
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thank you kind sir
0
Commented:
Thanks

this bit I edited wrong

// Is number between 6 and 50?
if(\$n<-11 && \$n>=-20) return "orange";

should be

// Is number between 6 and 50?
if(\$n<-10 && \$n>=-20) return "orange";

otherwise you will miss if the value is -11
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.