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

I'm going crazy over this code for two days!!!

I thought I was an idiot for a previous post.

I thought I was crazy when I saw the line about the letter in my code.

I thought I was one sick mf.

But when I replaced 'i' with 'g', things started to change:

<html>
    <p>
    <?php
    // Print out the position of a letter that is in
    // your own name
    print strpos('david','g');
    ?>
    </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', 'g') === false){
        return 0;
    }
    ?>
   </p>
</html>

See, this is the over 9000th attempt at making this code work. WHY!?

I get this error message:

 Your first strpos() call should output a number. 

Doesn't that output a number? Thank you for the help.

best,

armegetron


5 votes

permalink

This was ok in my case :D

  <?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

1 Comment

D74f3e8f6ac51c03fee857f664b33d34?s=140&d=retro sofiabeans27 over 2 years ago

Your so smart! thank you!


1 vote

permalink

Try this

<?php
// Print out the position of a letter that is in
// your own name
$myname = "david";
print strpos($myname, "v"); // put some letters from "david" - that's the task

?>
</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($myname,"g") === false)
{
    print "Sorry, no 'g' in 'david' ";
}
?>
</p>

581 points
Picture
Submitted by
Theo Arefb
over 2 years ago


0 votes

permalink

First thing I noticed is that it is, in fact not returning a number. In the first strpos, you need to define a letter that is in the word, or it won't return a number.
It should look something like this:
<?php
// Print out the position of a letter that is in
// your own name
print strpos('david','d');
?>
Onto the second php code block, I noticed that it is outputting an error message that doesn't really look like a helpful error message as it doesn't indicate that it is an error. This is what caused the "You should print out a helpful error message for the failed strpos" error. It should look something like this:
<?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', 'g') === false){
print "error";
}
?>

149 points
D211e78375dae368865699f019ca88c0?s=140&d=retro
Submitted by
ethanwdp Price
almost 3 years ago

1 Comment

47a42e5f695548436bbba4afd2d512a0?s=140&d=retro Joshua Paxton over 2 years ago

You can't use the first letter, it doesn't count 0 as a number (In my history)


0 votes

permalink

print strpos("Player","r"); I think you should add quotation mark instead

1056 points
54979a8d9376760508005d51_37156227
Submitted by
Player A. Player
almost 3 years ago


0 votes

permalink

Try this, I changed a couple things...

<?php
// Print out the position of a letter that is in
// your own name
print strpos("david","v");
?>


<?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", "g") === false){
print "0";
}
?>

630 points
47a42e5f695548436bbba4afd2d512a0?s=140&d=retro
Submitted by
Joshua Paxton
over 2 years ago