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

Code Challenge: stripos

The code is now displaying the right message. Thanks! Let’s change the second variable to a flavor that does start with C to make sure the code still displays the right message: change $var2 to Chocolate.

Oops! It looks like Task 1 is no longer passing.

I understand that 1 should no longer be passing because I changed the $var2, but not sure why it doesn't work for the new $var2.

<?php

    $var1 = "Cookie Dough";
    $var2 = "Vanilla";
    $var2 = "Chocolate";
    $initial = "C";

    if (stripos($var1,$initial) !== 0 && stripos($var2,$initial) !== 0) {

        echo $var1 . " and " . $var2 . " both start with " . $initial . ".";

    } else {

        echo "Either " . $var1 . " or " . $var2 . " doesn't start with " . $initial . "; maybe neither of them do.";

    }

?>

2 Answers

You have to change the value of $var2 instead of replacing it with a new $var2. If you create a new variable to try escaping by the error... I say you that in this period Treehouse has some problem with Code Challenges: for example, if (and other) statements doesn't work.

    $var1 = "Cookie Dough";
    $var2 = "Chocolate";
    $initial = "C";

    if (stripos($var1,$initial) !== 0 && stripos($var2,$initial) !== 0) {

        echo $var1 . " and " . $var2 . " both start with " . $initial . ".";

    } else {

        echo "Either " . $var1 . " or " . $var2 . " doesn't start with " . $initial . "; maybe neither of them do.";

    }

?>

Yea, this doesn't work either...