Math Functions II Problems


#1


This is about Math Functions II. I really don't understand why I keep getting the error "Oops, try again. The random output you printed from your name should be just one character". Any help would be greatly appreciated. Oh, and by thew way, I use $randC = round(rand(0, $length-1)); because it simply won't accept $randC = rand(0, $length-1); => it'll keep giving me the error " Oops, try again. Your printed output from rand() should be an integer."


<html>
    <p>
    <?php
    // Use rand() to print a random number to the screen
    print rand();
    ?>
    </p>
    <p>
    <?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
    $name = "stefan";
    $length = strlen($name);
    echo "<p>Chosen name has " . $length . " characters.</p>";
    $randC = round(rand(0, $length-1));
    echo "<p>Random character is character associated with string position no. " . $randC . ".</p>";
    $result = substr($name, $randC, 1);
    print $result;
    ?>
    </p>    
</html>


#2

dont print these lines

 echo "<p>Chosen name has " . $length . " characters.</p>";
    $randC = round(rand(0, $length-1));

and

echo "<p>Random character is character associated with string position no. " . $randC . ".</p>";

you just have to do what you are told to do :slight_smile:


#3

Thank you, rcodeman. Eliminating those lines does work, but the code was okay, right? It's just something related to the way Codecademy validates the results.


#4

yeah!!!!!!!!!!!!! :slight_smile:


#5

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