mercredi 17 février 2021

I am getting the wrong result for all ages above 5. I cannot use switch statements

This is the code in question. It seems right to me but it for all ages above 5, it outputs "You can go to preschool"

<?php

$age = 13;

if ($age < 3) {
    echo "You are too young for school";
} elseif ($age = 3 or $age = 4) {
    echo "You can go to preschool";
} elseif ($age >= 5 and $age < 12) {
    echo "You can go to primary school";
} elseif ($age >= 12 and $age < 18) {
    echo "You can go to high school";
} else {
    echo "You do not have to go to school";
}

?>

Aucun commentaire:

Enregistrer un commentaire