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 Task 2 of 2: Stripos

alt text

Challenge Task 2 of 2

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.

    $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.";

    }

?>```

2 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Trisha.

I think the error is here:

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

We actually want a code that checks that (stripos($var1,$initial)) is equal to the number 0, not different. And this applies to the second if check also.

The fact is that with your code you managed to pass the first step as

if (stripos($var1,$initial) !== 0 && stripos($var2,$initial) !== 0) this actually returns false in our case and the compiler follows then the right path.

Try this comparison statement instead:

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

That should work, but I hope you understand the reasons behind that, if not please ask me again.

;)

Worked! Thank you for explaining!!