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

Functions, Part I Forum

View Course

319 points
122bd223cdf305b062788bd6381b7a9e?s=140&d=retro
Submitted by
CHIEN-MING
almost 2 years ago

i have problem in PHP, Functions 5/8

i can't run~
it still shows "The random output you printed from your name should be just one character."
could u solve the problem?
thank you!

this is my code:

<?php
print rand ();
?>

<?php
$name = 'chien-ming';
print substr ($name, rand(0,strlen ($name)) , 1) ;
?>


1 vote

permalink

<?php

$name = "Liam";
print substr($name, rand(0, strlen($name)), 1);
?>

I completed the task using this code, which is almost identical to yours, try checking the spacing or use " " instead of ' '

758 points
2c0abd8c404a4dfc6fbda5ebf268e3e6?s=140&d=retro
Submitted by
doffylaw
almost 2 years ago

1 Comment

122bd223cdf305b062788bd6381b7a9e?s=140&d=retro CHIEN-MING almost 2 years ago

thank you


0 votes

permalink

print rand (1,10); should choose a range

$name = 'chien-ming';
print substr ($name, rand(0,strlen($name)-1 , 1) ; strlen($name) should substract 1 since string starts from 0,1 .... strlen($name) - 1.

67 points
Picture
Submitted by
Li Fang
almost 2 years ago