Math function II


#1



What is wrong with my code??

<html>
    <p>
    <?php
    echo rand();
    ?>
    </p>
    <p>
    <?php
    $name = "Sudeep Sagar";
     echo rand(0, 4);
     
    $num = rand(0, strlen($name)-1);
    echo substr($name, $num, 1);
    ?>
    </p>
</html>


#2

This line is not expected.


#3

First, the rand() function must have a min and max.

For the second part,

first you need to count the number of string of your name using strlen function, then use
the rand function, rand(0, $length)
then, you can now proceed to the substr function, substr(name, randomized number from your name, 1)
then there you have it.


#4

Not so. rand() will output an integer in the range of 0 to 32757. It might be that this exercise expects a min and max, though it is not specified.

There is nothing wrong in the second part.


#5

I have made changes to the first part but still same problem.


#6

By the way, I got through the exercise, the exercise wanted only one character to be printed after rand().


<?php
echo rand(0, 8);
?>



<?php
$name = "Sudeep Sagar";
$num = rand(0, strlen($name)-1);
echo substr($name, $num, 1);
?>



#7

Your first code that you set should work. He's good!


#10