For this lab please team up in pairs
Study the following examples: Introduction to conditionals Combining conditions
Copy/paste the source code of this page into a file
Add a conditional that, depending on the person's answer, displays one
of the two pictures. More specifically:
altattribute for an image
Change the program so that the lower-case y and n are also accepted as an answer. Do not add extra if/else, use || (means "or") instead. You need to write out both conditions and then connect them with ||. For instance,
is correct, but this is wrong:
if (n == 4 || n == 5) // correct
if (n == 4 || 5) // WRONG!
Write a program that uses a random number generator (see here) to generate a random number between 1 and 5. Then display one of six fortune messages, depending on the number. For instance, if the number is 2, your message might be "This is the luckiest day of your life!". Run your program several times to make sure it works.
Change your fortune-teller to increase the range of your numbers and make some messages more frequent than others by making them show up for more than one number. For instance, 1, 2, and 3 may all give you the same message, 4 and 5 give you a different one, and so on. Make sure that even the least frequent messages show up if you try your program long enough.
CSci 1001 course web site.
The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.