Your Task

Let us imagine that a human facilitator is equipped with a laptop, and is surveying people. The facilitator will use your program to:-

  • Enter the collected data.
  • Perform some calculations.
  • Display some results, including a summary of collected data in the form of a HTML table.

Diagram 1: The Three Parts of your Code. see image.

Your program has 3 phases, as shown in the diagram above:-

  • An input phase that collects the raw data.
  • A calculation phase, that begins when the input phase is finished.
  • A display phase that begins when the calculation phase is finished. It displays calculated data as well as raw data in the form of a HTML table.

Please dont allow these phases of your code to bleed into each other. The input phase should do input only. The calculation phase should perform intermediate calculations only. The display phase should display calculated data only.

The Input Phase

Diagram 2: The Input Phase. see image.

Your program must allow the facilitator to keep entering the detail for another person until the facilitator no longer wishes to. How you achieve that is up to you, but it must be easy to use and you need to make sure the user knows what to do.

You must perform interactive input by using the prompt() function (and possibly the confirm() function).

The Question Structure

Diagram 3: The Question Structure. see image.

For each person that the facilitator chooses to enter, you need to get the following from the user:-

  • The surname. (suggestion: .sName) The persons surname cannot be empty.
  • The given name. (suggestion: Name) The given name cannot be empty.
  • The biological gender. (suggestion: .gender) The gender must either be "male" or "female". (You can make this "M" or "F" if you prefer.)
  • The age in years. (suggestion: .age Yrs) The age in years must be an integer in the range 15 to 100.
  • The post code. (suggestion: .pCode) The post code must consist of 4 digits.
  • Employment Status. (suggestion: .emplyStat) The employment status must either be the word "employed" or the word "unemployed".

The facilitator (or your marker) should require no training prior to using your program. Make it clear to the facilitator what input would be valid. Keep it simple.

E.G. "What color is your car? Enter either the string "black" or the string "white"?

E.G. If you make it so that entering an empty string for a surname is what terminates the input loop, then make sure that is obvious to the user.

You should use the method trim() to remove leading or trailing spaces from user input.

The Calculation Phase

The calculation phase begins when the input stage is finished, and the display phase happens when the calculations have been performed. Your program must calculate the following collective data:-

  • Unemployment rate. Store it as a fraction. This is a floating point value.
  • Average age in years for unemployed men. This is a floating point value.
  • Average age in years for unemployed women. This is a floating point value.

The Display Phase

Your output will be written to the document using document.write() or document.writeln(). The use of alert() is not acceptable, and any occurrences of console.log() will be assumed to be debugging.

Otherwise, your program must output the following:-

  • The unemployment rate as a percentage.
  • The average age for unemployed men as a floating point number to one decimal place.
  • The average age for unemployed women as a floating point number to one decimal place.
  • A HTML table with all person's details, complete with headings, one person per table row.

If your dataset is the empty set, then this must be stated.

Requirements

Indentation

1. The code needs to be indented in one of

  • K&R
  • Allman
  • Horstmann

2. The indentation needs to be consistent throughout the code. One of the above styles needs to be applied to all of your code. It is permissible to mix Horstmann and Allman styles.

Block Commented

Your code needs to be block commented throughout:-

  • Code blocks separated by a single blank line.
  • Comment for block on lines immediately before block.
  • No blank line between comment and block that it applies to.

Naming Conventions

Naming conventions should be observed for identifiers:-

  • Constants are all UPPER CASE.
  • Variable and function names should be camelCased.

Value Types

You must demonstrate control over your value types:-

  • Convert your strings to numbers using parseInt() or parseFloat() where appropriate.
  • Do not apply parseInt() or parseFloat() to things that are already numbers or to things that are meant to be strings.
  • Do not apply arithmetic operations to strings or string operations to numbers.

Use Strict

Your code should be executed in strict mode. I.E. It needs to have "use strict"; directive at the start of your < script > section.

Order of code in your source code file

Variables need to be declared (possibly with initialisation) before they are used.

  • Put the Javascript code in a single < script > tag in the < head > tag section of your HTML document. Do not write any HTML in the body of the document. This will be generated by your JavaScript code.
  • In the script order your content as follows:
    • Constants.
    • Functions.
    • Global code.

Challenges

The following are challenges. They are meant to be challenging, and the marks here are definitely not "low hanging fruit", offering few marks for much work. Even so, you cannot get a "high distinction" in the assignment without attempting at least one of them.

It is recommended that you only attempt these if you have finished the non-challenge parts and are confident with your program thus far. Don't forget to save a working copy of what works.

Sort the Records

This challenge will give experience sorting an array of records and using a custom comparison function to achieve that.

As part of the calculation phase, sort the records using the surname as a primary field, and the given name as a secondary field. Your marker will be able to view the sorted records in the tabular output of your program.

Day of Birth

This challenge will give experience in extracting components from a string as well as extra validation experience.

In place of "years of age" you should request the date of birth.

  • The date of birth must be in the form "dd/mmm/yyyy", (e.g. "05/Nov/1978").
  • The date string must be fully validated:-
    • Split the string into its components:-
      • Convert the day to a number (e.g. nDay).
      • Convert the month string to a month index (e.g. iMth).
      • Convert the year to a number (e.g. year).
    • Use the components in a constructor for a date object.
    • Assuming that we created the Date object using:- let dob= new Date(year, iMth, nDay); then the following expression would check the date validity:- let isDobValid = (dob.getDate() == nDay && dob.getMonth() == iMth && dob.getFullYear() == year);
  • Store the date object, not a string.
  • The table displayed should still only include the age in years.

It is suggested that you write a function called getDate() that performs the input and validation of a date.

Unemployed and Under-employed

Diagram 4: The Expanded Employment Status. see image.

The entry of the employment status given above is simplistic. This challenge introduces a more realistic determination of employment status.

The entry of the employment status is to be expanded:-

  • There are two additional values for the employment status. Please implement and call a function to input the employment status as depicted in Diagram 4.
  • Your function should not use global variables.
  • Instead of just "employed" or "unemployed" your table will now show one of 4 possible employment status values as depicted.
  • Calculate and display both an unemployed rate and an under-employed rate.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.