Assignment3A.png
Figure 1: Sample form with data filled in and computation completed

ICT-4570 Homework 3

Purpose

This exercise allows you to use control logic in JavaScript, and to experience how arithmetic is done.

What to Hand In

Canvas submission instructions:
Please combine multiple files into a single "zip" archive, and save it in a location that you will remember. When you are ready to submit the assignment solution, open the assignment in Canvas, and click on the Submit for Evaluation button at the top, attach the file, and click Submit for Evaluation at the bottom.

Problems

  1. Politics and poker
    1. Build a simple form containing: Inputs for at least two candidate names, candidate parties, an "as-of" date, and places for raw vote counts.
    2. Also put on the form two output locations for total votes, and percentages for each candidate, which will be reported with 1 decimal place.
    3. The form should also have a button entitled Calculate which will tie to a function to read the inputs and place the output results.
    4. Be sure to add JavaScript logic to catch errors, or other, incorrect input and properly handle it:
      Unparsable dates and other errors should be reported or corrected upon pressing the calculate button. See notes for detailed checks.
    5. Your JavaScript functions should accomplish the following:
      • A function to look up an HTML element by id and return the element
      • A function which takes an Array of numbers as a parameter, and returns the sum.
      • A function which takes an Array of numbers as a parameter, and returns an array of percentages (see notes for this computation).
      • A function which formats a number into a percentage (see notes for this computation).
      • A function to collect all the vote counts and return an Array, ordered by candidate, of their vote counts.
      • A function to (a) collect all the counts; (b) get the sum of all votes; (c) compute the percentages for each candidate; and (d) place that result on the form in the correct locations.
      • A function to initialize the form by setting the date to the current date, and attaching the click action to the click button.

Notes

Evaluation

Criteria Weight
HTML and CSS, to create the form 40
JavaScript to read inputs and create output 40
Screenshots of results, including error cases. 20