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 trialAmin Khoshzahmat
12,342 Pointsstripos function
The code is now displaying the right message. Thanks! Letβs change both variables to words that do start with R to make sure the code still displays the right message: change $var1 to Rocky Road and $var2 to Raspberry.
<?php
$var1 = "Rocky Road";
$var2 = "Rasp berry";
$initial = "R";
if (stripos($var1,$initial) == 1 && stripos($var2,$initial) == 1) {
echo $var1 . " and " . $var2 . " both start with " . $initial . ".";
} else {
echo "Either " . $var1 . " or " . $var2 . " doesn't start with " . $initial . "; maybe neither of them do.";
}
?>
SO, What's Wrong Here?
1 Answer
tihomirvelev
14,109 PointsThe mistake is that you are comparing stripos to the index 1 but actually this is the second character from the word.
It has to be that way:
if(stripos($var1,$initial) == 0 && stripos($var2,$initial) == 0)
Hope that helps. Good luck!
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou passed task 1 but I don't see the change you were supposed to make to pass that task.
What change did you make to pass task1?