Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,275 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