This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

241 points
54d298c351b887cc8b0011d3_713998270
Submitted by
zimmermc
over 2 years ago

Question 5 - Getting error

Getting the following in the output screen.

Use of undefined constant zimmermc - assumed 'zimmermc' (line 12)r

On the editor screen I get the following error:

Oops, try again. The random output you printed from your name should be just one character.

Here is my code:

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


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


0 votes

permalink

This code worked for me.

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


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

1773 points
55616ff49113cb60980005d7_272186260
Submitted by
Alvin Padayachee
over 2 years ago


-1 votes

permalink

Hi,

$name contains a string, therefore you must contain it with " ".
Example, $name = "zimmermc";

The second error tells you the goal to complete the exercise. Where you must print only one letter.

833 points
8a92e078091bb8c4efaf17854372ad92?s=140&d=retro
Submitted by
Lorenzo Ferrante
over 2 years ago

1 Comment

54d298c351b887cc8b0011d3_713998270 zimmermc over 2 years ago

Oh my gosh! That was too obvious...Thank you! I feel so stupid having not caught that! LOL! Thank you!