Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,451 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