y did not understand, but i hope i help you

2010/4/9 Wally Kolcz <[email protected]>

>
>
> Thanks for the try, but all ages are > 18 so the first condition would be
> met on all of them. I need the multiple conditions on the case to be
> preserved. :)
>
>
> On 4/9/2010 11:45 PM, Rob Romanek wrote:
>
>
>
> This is off the top of my head in email so there may be some errors but
> something like this should work
>
>  var category:Number;
>
>  switch (true){
>  case(age > 18):
>  category = 0;
>  break;
>  case(age > 15):
>  category = 6;
>  break;
>  case(age > 12):
>  category = 5;
>  break;
>  case(age > 8):
>  category = 4;
>  break;
>  case(age > 5):
>  category = 3;
>  break;
>  case(age > 2):
>  category = 2;
>  break;
>  default:
>  category = 1;
> }
>
>  return category;
>
>  hth,
>
>  Rob
>
>
>
>  On 9-Apr-10, at 10:45 PM, Wally Kolcz wrote:
>
>    Can someone rewrite this as a switch/case? I tried, but it didn't seem
> to work. Problem I am running into is the multiple conditions in the
> case. Thanks!
>
> private function getAgeGroup(birthday:Date):int {
> var age:int = getAge(birthday);
> if (age >= 0 && age >3){ //Birth to 2
> return 1;
> }else if (age >=3 && age >6){ //3 to 5
> return 2;
> }else if (age >=6 && age >9){ //6 to 8
> return 3;
> }else if (age >=9 && age >13){ //9 to 12
> return 4;
> }else if (age >=13 && age >16){ //13 to 15
> return 5;
> }else if (age >=16 && age >19){ //16 to 18
> return 6;
> }else { //Older or Adults
> return 0;
> }
>
> }
>
>
>    
>

Reply via email to