Show what you know random array with uppercase


#1

I am stuck on final SHOW WAHAT YOU KNOW on functions.
I am getting the correct output, I am able to push a number of arrays and count and sort them.
I am also able to pick a random one and present it in uppercase.

https://www.codecademy.com/courses/web-beginner-en-7I7Xm/0/8?curriculum_id=5124ef4c78d510dd89003eb8#

But I get a reply "Oops, try again. Did you remember to use strtoupper() in your code?"


	<?php
	    $fav_planes=array();

array_push($fav_planes, "saab viggen");
array_push($fav_planes, "saab draken");
array_push($fav_planes, "saab gripen");
array_push($fav_planes, "saab lansen");
array_push($fav_planes, "saab tunnan");
print "Plane count is: " .count($fav_planes). "<br>";
    
	// Sort the list
sort($fav_planes);
print "Planes are: " .join(", ", $fav_planes) ."<br>";
	// Randomly select a winner!
	

$fav_planes = array_map('strtoupper', $fav_planes);
echo "Winner is: " .$fav_planes[array_rand($fav_planes)];

	// Print the winner's name in ALL CAPS
	
	
	?>


#2

If you've done every thing below, don't forget to wrap your code in p tags.

<p>
	<?php
	    $fav_planes=array();

array_push($fav_planes, "saab viggen");
array_push($fav_planes, "saab draken");
array_push($fav_planes, "saab gripen");
array_push($fav_planes, "saab lansen");
array_push($fav_planes, "saab tunnan");
print "Plane count is: " .count($fav_planes). "<br>";
    

print "Planes are: " .join(", ", $fav_planes) ."<br>";
	// Randomly select a winner!
	

//$fav_planes = array_map('strtoupper', $fav_planes);
//Although you are not wrong, but you are converting your whole array list to uppercase. 
//You only need to do this for one item in the list. The excercise don't  require the use of array maps.

//echo "Winner is: " .$fav_planes[array_rand($fav_planes)];
//you used array_rand() instead of using rand() to get the random list in the array 

// get the random number  using the count -1 since it is indexbased. The result is a random number stored in $random_number.

// Sort the list
sort($fav_planes);

$random_number  = rand(0, count($fav_planes) -1 );

//you just get the index using the random number and it prints the winners name  in all caps remember that the index list are strings so, we're just converting them to uppercase

print "Winner is: ".strtoupper($fav_planes[$random_number]);


	
	?>
</p>

#3

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