Lab Exercises

A series of laboratory exercises. We will work on these in class on 3/10 and 3/12.

Baseball Statistics

Baseball season is upon us. Design and program an HTML form that calculates the following baseball statistics:

  • Batting average (BA) is calculated as hits/at bats. So you would have to input the number of hits the player had and the number of at bats. The average is represented as a real number between 0 and 1. For this exercise, the form should have two input text fields, one for hits and one for at bats. It should display the result and present the form on the same page so that another batting average can be calculated without going back to the form.

Click here for the solution.

  • Earned run average (ERA) is calculated as the number of earned runs allowed per nine innings. For example, if a pitcher allowed 1 earned run in 3 innings, his ERA would be 3.

Dollars to Euros

  • Currently the exchange rate is something 1.52 U.S. dollars per Euro. Design and program an HTML form that will allow the user to convert in either direction, from dollars to Euros and vice versa. Also, the form should contain a select input that displays several conversion rates -- e.g., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, and so on. There should be a default rate in case the user doesn't select a rate, and whatever rate the user selects should used in the conversion.

Click here for a solution.

See Also