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 trialDominic Houghton
5,349 PointsAdding Search: Model > Using stripos: Starts with R > task 2 of 2
After completing task 1 of 2, the task simply asks you to change two variables to two defined values to test the code. When I do this, it says;
Oops! It looks like Task 1 is no longer passing...
4 Answers
Randy Hoyt
Treehouse Guest TeacherWould you mind sharing your code?
Dominic Houghton
5,349 PointsHi Randy. Sure.
<?php
$var1 = "Rocky Road";
$var2 = "Raspberry";
$initial = "R";
if (strpos($var1,$initial) == 1 && strpos($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.";
}
?>
Randy Hoyt
Treehouse Guest TeacherIt looks like you made the wrong change in step 1 to get it to pass. You need to use the stripos
function, but something else needs to change. Why would it think that broccoli starts with R? What number does the stripos function return if a word does start with the letter specified?
Hint: Does broccoli have an R anywhere in it? Not at the beginning but somewhere else?
Dominic Houghton
5,349 PointsAH!
A forehead slap moment....
You had it set as
if (stripos($var1,$initial) == 1 && stripos($var2,$initial) == 1) {
so replacing == 1 with == 0, it is now checking that the returned number from the stripos function matches the first character as apposed to the second character.
Thanks for your help. Look forward to your next installments Randy! learned more in the past 7 days then I have in 7 months.