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

Control Flow: Switch Forum

View Course » View Exercise

910 points
56787a4c51b887e1ea000482_470000555
Submitted by
Ryan Palmer
almost 4 years ago

Why does this print, but not pass me?

I get the right answer, but it states that I didn't make an if statement. How come?

here is my code

<!DOCTYPE html>





<?php

if (3 > 2) {
echo "This is true";
} else {
echo "This is so wrong";
}

?>
</body> 

5 votes

permalink

Ryan's code works if you add the elseif statement like so:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
    <?php
    if (3 > 2) {
echo "This is true";
}
elseif {
 echo "That is half true and half wrong";   
}
else {
echo "This is so wrong";
}
    ?>
    </body>
</html>

1078 points
52dc922a52f8630a5a001008_322480677
Submitted by
ninjakid
almost 4 years ago


2 votes

permalink

Hello, I believe they want that you compare variables.
Try it:
<?php
$num2 = 2;
$num3 = 3;
if ($num3 > $num2) {
echo "This is true";
} else {
echo "This is so wrong";
}

616 points
50ddaa4cf62ddbd71700a145_667138907
Submitted by
Deividy
almost 4 years ago

2 Comments

5549be5886f5524a98000271_445473913 Khairul Akmal over 3 years ago

You need to include the elseif() statement as well.

175f8d348368011a0516c810f8a099f2?s=140&d=retro leverance over 3 years ago

yep elseif and compare some variables and it will pass


0 votes

permalink

The code is correct.There might be an error for the site to fix.

1281 points
4237d5b4403c12eb88e5bccaba435641?s=140&d=retro
Submitted by
Waseef Akhtar
almost 4 years ago


0 votes

permalink

thanks i fixed it.

910 points
56787a4c51b887e1ea000482_470000555
Submitted by
Ryan Palmer
almost 4 years ago


0 votes

permalink

Hey I think you have to either have a variable or a "elseif" statement try this. In this code I covered everything

<!DOCTYPE html>

<?php
$XFruit = 10;
$Y
Fruit = 11;
if ($XFruit == $YFruit) {
echo "You have the same amount of X fruit as Y fruit";
} elseif ($XFruit > $YFruit) {
echo "You have more X fruit then Y";
} elseif ($XFruit < $YFruit) {
echo "You have more Y fruit then X";
} else {
echo "You have the same amount of both fruit";
}
?>

275 points
513a6853cba712ed81001bff_337837668
Submitted by
Wojtek Hordyniec
over 3 years ago