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 trialCoders Unlimited
10,112 PointsStruck on cc task2
<?php
$var1 = "Rocky Road ";
$var2 = "Raspberry";
$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.";
}
?>
4 Answers
Joakim Bergman
14,501 PointsI might be wrong but I think stripos() is zeroindexed. In other words try to compare it to 0 instead of 1.
Coders Unlimited
10,112 Pointshey this code work for me you can try it.....
$var1 = "Rocky Road "; $var2 = "Raspberry"; $initial = "R";
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.";
}
Richard Duncan
5,568 PointsSpits out: Rocky Road and Raspberry both start with R.
What's the issue here?
Coders Unlimited
10,112 Pointsya we have to change those thing in this task and also assign the condition "==" not "===" that is the mistake in previous code...
Richard Duncan
5,568 PointsYes you should use the identity operator === for comparing to 0 but I checked that before my previous comment and the result is the same string.
Coders Unlimited
10,112 Pointsyes same only the thing is if they give another task for comparing there we can easy to find the answer.