CS 1 - Lab 5

Outcomes:

Upon completion of the lab, the student will know how to:

1.

For this lab you will use the random.js library to write some web applications.

  • Create an HTML file for this lab assignment called lab5.html (See the instructions for Lab 2 if you are unsure how to do this.)
  • Download the random.js file here and save it to your jump drive in the same place you put the HTML file.
  • In order to use the functions in the random.js library you will need the following HTML in the head tag in addition to any script tag you add in later:
    <script type="text/javascript" src="random.js"></script>
                      
  • We will write two applications in today's lab: An ESP tester and a six-sided die roller.

2.

Our first application is the ESP tester

  • The traditional test for determining whether someone has ESP (extrasensory perception) involves asking the person to guess randomly selected numbers.
  • Your application will have four buttons labeled "Guess 1", "Guess 2", "Guess 3", and "Guess 4".
  • It will also have a text box that displays the results of the test.
  • You must implement a function called PickNumber which does the following:
    1. Picks a number between 1 and 4 using the RandomInt function from the random.js library.
    2. Prints a message to the text box containing the users guess along with the machine's random selection.

3.

Our second application is the six-sided die roller

  • First you will need to download the following files to your jump drive:
  • Use an image tag to display die1.gif on your web page
  • Write a function called RollTheDice that picks which side of the die to display.
  • The simplest way to do that is to use the RandomOneOf function with the following argument (including the square brackets):
    ["die1.gif", "die2.gif", "die3.gif", "die4.gif", "die5.gif", "die6.gif"]
  • This will give you a string that you can use to set the src attribute of your image.

4.

When you are done, upload the lab5.html file to the CS server using FileZilla. (See the instructions for Lab 1 if you are unsure how to do this)