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

Functions, Part I Forum

View Course » View Exercise

949 points
Cf5bb7b5d1cb943783594b07036e365d?s=140&d=retro
Submitted by
Justin Enayati
over 4 years ago

Why does nothing pass in this exercise ??

<?

$fav_bands = array();
array_push($fav_bands, "Maroon 5");
array_push($fav_bands, "Bruno Mars");
array_push($fav_bands, "Nickelback");
array_push($fav_bands, "Katy Perry");
array_push($fav_bands, "Macklemore");

        print count($fav_bands);
?>

i literally copy and pasted the exercises own examples to pass after my own push arrays were not counting.

still with no success :(.

i have restarted the browser and all the normal things .. and this passes for me and works on my live server and notepad++.

anyone have this problem or a solution ? any suggestions ??


11 votes

permalink

I wrote this:


<?php
$array = ();
arraypush($array, "a");
array
push($array, "b");
arraypush($array, "c");
array
push($array, "d");
array_push($array, "e");
print count($array);
?>

But only if you use $fav_bands and the examples on the side, you will pass. Or at least that did the trick for me.

<html>
    <p>
    <?php
$fav_bands = array();
array_push($fav_bands, "Maroon 5");
array_push($fav_bands, "Bruno Mars");
array_push($fav_bands, "Nickelback");
array_push($fav_bands, "Katy Perry");
array_push($fav_bands, "Macklemore");
    print count($fav_bands);
    ?>
    </p>
</html>

Does this solve your problems?

1135 points
649aee554df9ff8be6247ff09b774776?s=140&d=retro
Submitted by
Philipp Schön
over 4 years ago

3 Comments

D14be167e66508b3d44e7c8eec387dc0?s=140&d=retro leopoldoab over 4 years ago

the same occurs to me, if i wrote fav_bands can pass this exercise

3e3920b75a3c57b6760d1303301f685b?s=140&d=retro Mohsen Qaddoura over 4 years ago

you made an error in the start tage you missed the php!! so instead of just <? you should have <?php

3e3920b75a3c57b6760d1303301f685b?s=140&d=retro Mohsen Qaddoura over 4 years ago

Always when copying make sure you didn't miss anything,and honestly it will be beneficial to always type the code manually. It will help you catch such errors and observe details you do not normally notice by just reading.This is also recommended strongly by great teachers of programming .


0 votes

permalink

same issue here. copied the example and it breaks. the only thing that worked for me was to delete the comments, then it passed. which makes no sense to me.

1374 points
Bdc303e4b8d72f5897335057d7c8a768?s=140&d=retro
Submitted by
Jeff Shamley
over 4 years ago


0 votes

permalink

Refresh Button, copy the code you have first. Paste it back in, it worked for me.

1558 points
512f013da423436d8f008c8b_487206984
Submitted by
Todd Hartsfield
over 4 years ago


0 votes

permalink

Not sure why the OP code didn't work, but I didn't have to copy/paste the example - this code worked fine for me:

$sports = array();

array_push($sports, "Soccer");
array_push($sports, "Hockey");
array_push($sports, "Basketball");
array_push($sports, "Netball");
array_push($sports, "Archery");

$result = count($sports);
echo $result;

250 points
4a75b234487d7adeef96f3cf30586935?s=140&d=retro
Submitted by
Dave Hickman
over 4 years ago


0 votes

permalink

I had to put a space between the push arrays and the print statement.

<html>
<p>
<?php
// Create an array and push 5 elements on to it, then 
// print the number of elements in your array to the screen

$favbands = array();
array
push($favbands, "Maroon 5");
array
push($favbands, "Bruno Mars");
array
push($favbands, "Nickelback");
array
push($favbands, "Katy Perry");
array
push($fav_bands, "Macklemore");

print count($fav_bands);
?>

1367 points
51a12ba5ce18ad3a8400004d_191292684
Submitted by
Chase Palmer
over 4 years ago

1 Comment

52565eeb80ff337232001e7d_158831513 brennanpringle_4f151ba89c99ab0001018 over 4 years ago

There are a couple errors here. First you are missing the underscore in "arraypush()", and second you need to remove the underscore in the last two "$favbands" variables.