Message -"Your printed output from rand() should be an integer. "


#1

Hi, everyone!
I'm stuck( This is my code:

<?php

print rand(1, 100)
?>

<?php
$name="Walter";
print substr($name,rand(0, strlen($name)-1),1);
?>

But everytime i see "Oops, try again.Your printed output from rand() should be an integer."
Any ideas what's wrong?


#2

I have the same problem, I think this is a bug of the system.


#3

same happened to me, after that i got an error message pointing to the line of the

- which isn't anything I had touched at all.

#4

I think that you need to use round() on the rand(), so that it doesn't come out to come out as a decimal. Otherwise the substr() has to print that decimal of your name


#5

u probably wrote your function for letter of name just below your first code for rnd number,
use second paragraph for it


#6

Yea I have the same problem. How can I complete the course like this? Yet they offer me services to pay for?


#7

I’m getting this error too, I don’t have the option to report a bug as I usually do. There isn’t an option for sample code either but this is a bug. Sort it out codecademy!


#8

<?php // Use rand() to print a random number to the screen print rand(40,50); ?> [details=Summary]

Summary

This text will be hidden

[/details]

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

#9

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

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

</p>

#10

Yes what the ■■■■ is going on??? How can I complete course? Ive been stuck on this forever.

Here is my code:

    $name = 'Preston';
    $strlen = strlen($name);
    $num = rand(1,$strlen);
    $randlett = substr($name, $num, 1);
    print $randlett;

I reset the code and reenter same code and it works correctly, selecting a random letter from my name everytime. Am I writing php incorrectly or is this a bug? HUUUUUUUUGE HEADACHE!


#11

WOW I finally got this to work. The secret was to break up my code to where the random number showed within the first paragraph and the random letter shows in the second paragraph…

Here is my final code that worked:

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

#12

i think there’s a problem with this part,. because it says that you should print the string into uppercase. but it printed an integer how can you make it into uppercase? unless you can convert the integer into specific string.

ps: sorry for my english.