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

Control Flow: Switch Forum

View Course » View Exercise

1555 points
Picture
Submitted by
Daniel Taggeselle
about 4 years ago

little problem

Hi folks,

i need a little help. Maybe its not a big thing but here is my code

<?php
$time = $start
$start = 20

    if ($time == $start) {
        echo "Time for The Croods";
    } 
    elseif ($time < $start) {
        echo "To early, relax!";
    }   
    else {
        echo "OMG!!! you got to late... arhg!!";
    }

?>

i get the following message:

PHP Parse error: syntax error, unexpected T_VARIABLE in /root/adapter/runners/runner.php(47) : eval()'d code on line 9

(line 9 is $start = 20)


2 votes

permalink

<?php
$teabags = 6;

    if ($teabags > 5) {
      echo "There are tea bags! I'll have a cup!";
    }
    elseif($teabags == 1)
    {
      echo "No more tea! I guess I won't have a cup.";
    }
    else
    {echo " i love you!";}
?>
</body>

380 points
5144880a4c0db0abe2003aa9_457460673
Submitted by
Rick
about 4 years ago

2 Comments

5144880a4c0db0abe2003aa9_457460673 Rick about 4 years ago

i Promotion by it

5144880a4c0db0abe2003aa9_457460673 Rick about 4 years ago

maybe it can help you


1 vote

permalink

You forgot a semicolon after defining your variables and $start needs to be defined before $time.

504 points
2b153953ef015ea1708bd5f306bd2bb6?s=140&d=retro
Submitted by
Roni
about 4 years ago

2 Comments

4d47c496e94ad8fa8d7a32c3f5c6f9ad?s=140&d=retro Ari Ogoke about 4 years ago

Thanks Aaron y!

I see another problem... What is the value of the $time variable after the first assignment statement? In other words, what was the value of the $start variable before it was assigned the value of 20 in the second statement.

2b153953ef015ea1708bd5f306bd2bb6?s=140&d=retro Roni about 4 years ago

If a variable isn't defined, it's NULL and it throws a "Notice: Undefined variable." You can use isset($variable) to check if a variable is defined. If the $start would be defined before $time, both of them would be "20", sorry if this doesn't help, didn't quite understand your question ;D