Thanks for the catch on the GT. Haven't tried to run it yet. Just wrote
is and hoped there would be a switch/case that is easier than having to
case out each age..
On 4/9/2010 11:43 PM, Joe wrote:
it curious but a person who are 2000 years old, with your
implementation it's group 1
run this code:
package
{
import flash.display.Sprite;
public class test extends Sprite
{
public function test()
{
trace(this.getAgeGroup(2000));
}
private function getAgeGroup(age:Number):int {
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;
}
}
}
}
maybe you want to do this:
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;
}
}
see i changed yours ">" with "<" ???
HOWEVER, a switch implementation is like this:
private function getAgeGroup(birthday:Date):int {
var age:int=getAge(birthday);
switch (age) {
case 0 :
case 1 :
case 2 :
return 1;
break;
case 3 :
case 4 :
case 5 :
return 2;
break;
case 6 :
case 7 :
case 8 :
return 3;
break;
case 9 :
case 10 :
case 11 :
case 12 :
return 4;
break;
case 13 :
case 14 :
case 15 :
return 5;
break;
case 16 :
case 17 :
case 18 :
return 6;
break;
default :
return 0;
break;
}
}
Point for testing!!!!! :D
greetings from Chile!, Latin America
_