PHP PHP Arrays and Control Structures PHP Conditionals Comparison Operators

Why when score is 59.5 it still display the massage?

Hi, In this video we see that the score is set to 59.5 and it still give us the first echo. My question is why is this happening? we get this line because 59.5 is technically higher than 59 but still in the same "scope" lets say?

$score = 59.5;
if($score > 59) {
    echo "You completed the level!";
} else if($score <= 30) {
    echo "You should pratice some more to pass this LEVEL :]";
}else {
    echo "Please try again!";
}

thanks in advance!

1 Answer

Steven Parker
Steven Parker
195,447 Points

As you say, "59.5 is technically higher than 59" and that satisfies the first test and produces the first echo.

If you want it to respond only to scores of 60 and higher, test for ">= 60" instead of "> 59".

My bad. i understand it now