5. random got stuck. please help


#1



<html>
    <p>
    <?php
    // Use rand() to print a random number to the screen
    $name = "ericjinsu";
    print $name;
    ?>
    </p>
    <p>
    <?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.

$length = strlen($name);
$rand = rand(0, $length - 1);
$letter = substr($name,$rand, 1);
print substr($name, rand(0,strlen($name)-1), 1);
    ?>
    </p>
</html>


#2

Study the following to see the difference...

<html>
    <p>
    <?php
    // Use rand() to print a random number to the screen
    print rand(1,10);
    ?>
    </p>
    <p>
    <?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.

    $name = "ericjinsu";
    //print $name;
$length = strlen($name);
$rand = rand(0, $length - 1);
$letter = substr($name,$rand, 1);
print substr($name, rand(0,strlen($name)-1), 1);
    ?>
    </p>
</html>

It is possible to refactor the second part...

<p>
    <?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
    print substr("Weegillis",rand(0,strlen("Weegillis")-1),1);
    ?>
    </p>

#3

I used your answer to solve my similar problem with this task, however i was receiving errors.
the final solution that i used was the following

$name = "myname";
$length = strlen($name);
$letter = substr($name, 1);
print substr($name, rand(0, strlen($name)-1), 1)
?>


#4

Whatever errors you received, you caused. I've used this syntax in four foreign language courses and passed every one.


#5

This is not an attack towards your code bro, no need to feel offended.
Was just mentioning how there was surplus code which only possible outcome was a higher chance of not passing this assignment.


#6

The only thing needed to pass this assignment is the correct output.


#8