Where is the mistake?


#1



<?php
// Use rand() to print a random number to the screen
print rand(5,6582);
?>



<?php
// Use your knowledge of strlen(), substr(), and rand() to
// print a random character from your name to the screen.
$name = "sona";
print rand(substr($name,strlen($name)-1,3),3);

?>
</p>

Please help me with my coding. I do not really understand what the heck with this code.

`


#2

https://www.codecademy.com/en/courses/web-beginner-en-7I7Xm/0/5

The substr() function takes three arguments...

substr( $string, $start_index, $length )

For the string, we use our name in this exercise. The start will be a random number, and the length will be 1. So this means rand() will be inside the substr argument list.

substr( "Wee Gillis", rand(), 1)

Now for a range to use in the rand() arguments. The function takes two of them,

rand( $min, $max)

The min will be the starting index of the string, 0, and the max will be the string length minus 1. So,

rand(0, strlen("Wee Gillis") - 1)

Substituting this into our substr expression above should give us a working expression.


#3

Thanks a lot :slight_smile: i am very grateful


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.