Updated 2/25/2020 at 6:25pm
Homework #5: Loops and Arrays
-
Remember to follow all the standard Homework Requirements.
- This assignment will demonstrate:
- Statement of the challenge:
-
Make a "Portfolio" page for your class Web site. Name it portfolio.php.
-
Put an HTML link on your index.php page, which allows someone to navigate to your new
"Portfolio" page.
-
Add some code to your Portfolio page that "deals" a poker hand, or displays a random set of
five images from a much larger collection of images.
-
I suggest that you put your code inside the <div> tag that has the id="contentDiv" attribute in it.
Look for this div between the breadcrumbs and the footer.
- You can use playing card images from any of the following locations. I suggest that
you unzip these images into your site's images directory.
Or, if you don't want to use playing-card images, you can use any other large collection of images
(around 50 images). Just make sure the images are not offensive, illegal, or defamatory.
- If you are using images of playing cards, you don't need to actually play any poker hands on your page.
Simply make it so that each time the page
is loaded or refreshed, it "deals" and displays a new hand of cards. A poker hand is
five cards. So you will need to "deal" five random cards each time
the page is refreshed or loaded.
If you are using some other collection of images, make sure that each time the page is refreshed,
you display a different, random set of five images.
-
Upload the saved page portfolio.php to your class Web site.
-
Test your page on the PHP Web server by clicking your student number on the
"Student Sites" page of this class site. Display your Portfolio page. Make sure your images display
properly.
-
EXTRA CREDIT: I will award you an additional 50 points if you can
make the code generate a new set of unique (meaning: no duplicated)
images each time the page is refreshed.
But if you don't want
to take on this challenge, don't worry about it. You will get full credit
for the assignment if duplicate images show up in the page, as long as the
images are in random order.
- HINTS:
- Use an array to build the set of images. Refer to the section "Array as Index
Storage" in the e-handout "Loops and Arrays". You can make an array of five elements, and
store an index (between 0 and 51) in each element of this "index" or "image set" array.
- Use another array to store the image file names. Remember that there are 52 cards in a deck, or if you
are using a different collection of images, make sure it is a rather large collection (about 50 images
or so).
- Use the rand(
) or the array_rand( ) function to build the set of five images. (See the first hint.)
- When the set of images is built, display the images with another loop, probably another for loop. Use
the indexes that you put into the "set" or "index" array, to determine which five
images to display.