# Functions, Part I: 5. Math Functions II --- rand() output should be an integer error?

#1

The task asks you to print a random character from your name to the screen, for which my code below correctly works, however it does not pass.

The error I receive is: 'Oops, try again. Your printed output from rand() should be an integer.'

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

The second argument of my substr() function IS an integer. Am I missing something?

#2

There are two parts to this exercise. The first part has us print out a random number. Did you complete that part of the exercise?

#3

I totally missed that part... Thanks haha. BTW, the random integer to be printed must be printed within the first php call, not the second one.

#8

A post was split to a new topic: Where exactly is the issue in the code?

#9

Hey thanks for this. I knew I had it right but for some reason, the thing is still saying I'm wrong. I'm stuck here and never had this issue before where the forums didn't solve. Here's my code. Oh and just to clarify what I'm seeing here, there's no need for round as integers are printed either way.

<?php
// Use rand() to print a random number to the screen
echo round((rand(1,6)));
?>

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

#10

Remove the `round()` as you say, and copy the code. Then refresh, paste back in if necessary and submit again.

#11

Thanks! I figured that out right after I posted and I can't believe I missed that! Yea it worked cause I'm nearly finished now. Doing the second half functions is fun.

#12

Thank you so much, it been over a week on this very problem. Unknowingly to me, I failed to attempt the first part of the question. Your response is still very relevant even after year plus:+1:

#14