This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Control Flow: Switch Forum

View Course » View Exercise

440 points
20fcc657596c13931eefd016d9c066d1?s=140&d=retro
Submitted by
dezignator
over 2 years ago

why this code isn't working for if/else-if/else

$number1=3;
$number2=6;
$number3=9;

if($number1>$number2 && $number1>$number3)
{
echo "number1 is biggest";

}
else
{
if($number2>$number3)
{
echo "number2 is biggest";

}
else
{
echo "number3 is biggest";

}
}

output is correct but it says "Are you sure you made an else if condition?"

yeah i made the right use of else if condition .. check it if i am wrong.

thank you.


0 votes

permalink

Change your middle bit here:

else
{
if($number2>$number3)
{
echo "number2 is biggest";
}

to

elseif($number2>$number3)
{
echo "number2 is biggest";
}

elseif is what you want. not an if within an else.

561 points
8d13a34c76a6c65b01c63591b0f984c1?s=140&d=retro
Submitted by
mbinfl
over 2 years ago