Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Jackson
5,644 PointsStumped on code Challenge...
I have been trying to get through this code challenge for a few days and I am completely stumped right now. Can someone tell me why my code won't pass?
function mimic_array_sum($array) {
$total = 0;
foreach($array to $element) {
$total = $total + $element;
}
return $total;
}
$palindromic_primes = array(11, 757, 16361);
echo mimic_array_sum($palindromic_primes);
?>
2 Answers
Erik McClintock
45,783 PointsAaron,
In your foreach loop, you have the keyword "to" - this should be "as".
Try that and see if it passes?
Erik
Aaron Jackson
5,644 PointsThanks Erik that was the problem!!
Erik McClintock
45,783 PointsGlad I could help! Happy coding!
Erik
Erik McClintock
45,783 PointsErik McClintock
45,783 PointsBeyond that, if you've gotten to the third section of the challenge, it wants you to store the value returned by mimic_array_sum into a variable called $sum, and then wants you to echo that value to the screen.