");
} else {
$userAge = $_POST["ageInput"];
$birthYear = date("Y") - $userAge;
if ($userAge < 0) {
print("Please enter a valid age above or equal to 0");
} else {
print("Your age is " . $userAge . "
");
// Two ways to determine even-ness
$isEven = ($userAge % 2 === 0) ? "Your age is even
" : "Your age is odd
";
print($isEven);
// OR
// if ($userAge % 2 === 0) {
// print("Your name is even
");
// } else {
// print("Your name is odd
");
// }
// Print age "category"
if ($userAge <= 12) {
print("You are a child
");
} else if ($userAge > 12 && $userAge <= 17) {
print("You are a teenager
");
} else if ($userAge > 17 && $userAge <= 54) {
print("You are an adult
");
} else {
print("You are a senior
");
}
// Print significant events with switch statement
switch ($birthYear) {
case 1969:
print("You were born the same year as the moon landing
");
break;
case 1983:
print("You were born the same year as the creation of the internet
");
break;
case 1986:
print("You were born the same year as the Challenger explosion
");
break;
case 2000:
print("You were born the same year as Y2K
");
break;
case 2020:
print("You were born the same year as the COVID-19 pandemic
");
break;
default:
print("You were not born in any significant year
");
break;
}
// Print age number of hearts
for ($i = 0; $i < $userAge; $i++) {
print("♥");
}
print("
");
// Print 100 - age number of stars
for ($i = 0; $i < (100 - $userAge); $i++) {
print("☆");
}
print("
");
}
}
?>