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

Functions, Part I Forum

View Course » View Exercise

678 points
Picture
Submitted by
Christopher Salay
about 3 years ago

Why isn't my code working?

<?php

// Print out the position of a letter that is in
// your own name
strpos("Christopher", "o");
?>
</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("Christopher","o") === false){
    print "Sorry, no 'o' in 'Christopher' ";
};

?>

5 votes

permalink

print strpos("Christopher", "o");

520 points
5461859b631fe9449d000ddc_826809439
Submitted by
Mathew Beck
almost 3 years ago


0 votes

permalink

if(strpos("Christopher","x") === false){
print "Sorry, no 'x' in 'Christopher' ";

520 points
5461859b631fe9449d000ddc_826809439
Submitted by
Mathew Beck
almost 3 years ago


0 votes

permalink

Since your name has 10 strings: it should be strpos (2);
For the position of “r”

93 points
2e180e2576b3bfc1dd5315b20e805907?s=140&d=retro
Submitted by
SergBarros46
over 2 years ago


0 votes

permalink

You do have an "o" in Christopher, so that is not a false statement.

// Check for a false value of a letter that is not
// in your own name
and print out an error message

Also put print before strpos("Christopher", "o"); So it will output the numbers.

520 points
5461859b631fe9449d000ddc_826809439
Submitted by
Mathew Beck
almost 3 years ago

4 Comments

D241245eab9265604f4d4c10d3e013b5?s=140&d=retro Eriberto Torres almost 3 years ago

I followed the code colleague and fixed it, but just sends error.
It's my code:
<?php
// Print out the position of a letter that is in
// your own name
strpos("Christopher", "o", 0);
?>


<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message

if(strpos("Christopher","h") === false){
print "Sorry, no 'o' in 'Christopher' ";
};

?>

And her error: Oops, try again. Your first strpos() call should output a number.

5461859b631fe9449d000ddc_826809439 Mathew Beck almost 3 years ago

I am having a hard time reading what you said. But if you changed the letter o to h then it still will not work because there is an h in Christopher.

D241245eab9265604f4d4c10d3e013b5?s=140&d=retro Eriberto Torres almost 3 years ago

Thank you. You solve my issue. :) Thank you very much. Now, I can continue studing :)

5461859b631fe9449d000ddc_826809439 Mathew Beck almost 3 years ago

Your welcome! :)