This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

400 points
Picture
Submitted by
Zach Perkins
over 2 years ago

I've spent a couple hours on this, tried different browsers, still can't figure out what's wrong.

I'm given the error "Oops, try again. You should print out a useful error message for the failed strpos() call." when running the code. I can't tell what is wrong. Help?

<?php
// Print out the position of a letter that is in
//your name
$name = "Zach";
$letter = "a";
$pos = strpos($name, $letter);
print $pos;
?>


<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message
$letter = "t";
if ($pos == false){
print "Sorry, no 't' in 'Zach'";
}
?>

2 votes

permalink

// Try this approach
// It worked for me

<?php
// Print out the position of a letter that is in
// your own name
$haystack=strpos("Zach","a");
print $haystack;
print "hay";

?>


<?php
if(strpos("Zach", "t") === false) {
print "Sorry, no 't' in 'Zach'";
}
?>

791 points
6e50938c8dd8b84872eb7734f68574a8?s=140&d=retro
Submitted by
RikShep
over 2 years ago

5 Comments

Picture Zach Perkins over 2 years ago

I just tried it with your code in both Safari and Chrome and it still didn't work for me

6e50938c8dd8b84872eb7734f68574a8?s=140&d=retro RikShep over 2 years ago

don't know what to say then. I tried that exact code with the exception of my name instead of yours and it worked fine for me

5ce0bca9764f7392679cfd8cf7755273?s=140&d=retro SamaAs over 2 years ago

Thank you very much!
For me worked fine.

45ee164e9fa1b5859479ed82e81ee80c?s=140&d=retro zhulan about 2 years ago

I guess it works differently on different browsers or different type of computers.

45ee164e9fa1b5859479ed82e81ee80c?s=140&d=retro zhulan about 2 years ago

because it didn't work for me and I have an apple computer.


0 votes

permalink

I tried RikSheps code and it doesn´t work, then i removed the: print "hay";
and it worked.

514 points
Cbadd5f534ea698d0f4a98fc15b20a64?s=140&d=retro
Submitted by
xMichi1996x
over 2 years ago