Response does not equel input


#1

So working on the functions part I exercise, the one where it asks you to print the random value of the position in a string. Okay straight forward. Need to think out the approach, but nothing major.

Step 1: declare a string:
$name = "my name";

step 2: find the length of the string:
$length = strlen($name);

step 3: find a random position from the length
$pos = rand(0, $length);

step 4, print that value:
print $pos;

so finished code:

$name = "MyName";
$length = strlen($name);
$pos = rand(0, $length);
print $pos;
?>

And the response I get from the system is:

"Oops, try again. The random output you printed from your name should be just one character. "

um.... well it IS one character. So... what am I doing wrong?


#2

I had the same issue. Here is what i did:



<?php
// Use rand() to print a random number to the screen
rand(15); <--- I entered this in my code and submitted it and it worked.
?>



<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$name = "Brian";
$strlen = strlen($name); // 7
$rand2 = rand(0, $strlen -1); // from 0 to 6
$substr = substr($name, $rand2, 1);
print $substr;
?>