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

Functions, Part I Forum

View Course » View Exercise

791 points
0047796cd1fc7f59a2c0da1bd830c9aa?s=140&d=retro
Submitted by
armegetronIsFun333
almost 3 years ago

This code should work!!!

<html>
    <p>
    <?php
    // Print out the position of a letter that is in
    // your own name
    print strpos('david','i');
    ?>
    </p>
    <p>
    <?php
    // Check for a false value of a letter that is not
    // in your own name and print out an error message
    if (strpos('david', 'i') === false){
        print "Sorry, no 'i' in david";
    }
    ?>
    </p>
</html>

but I get this error message:

You should print out a useful error message for the failed strpos() call. 

0 votes

permalink

That s because you are printing out "Sorry, no 'i' in david" but truth is there is i,
try with different letter for example k end change message to "Sorry, no 'k' in david"

or try this it worked for me

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

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

637 points
Picture
Submitted by
Vjekoslav Barić
almost 3 years ago