JavaScript Assignment

Order Description

The assignment problem is straightforward. All necessary details have been supplied. The solution of theproblem will be straight line code which will use the programming concepts and strategies covered in

Workshops 1-3. The subgoals are:

- Understanding values, variables and constants, Objects, Operations, and Functions

- Translating simple design into JavaScript code

- The mechanics of editing, interpreting, building and running your program

- Testing your program

- Commenting your source code

- Becoming confident and comfortable with programming in small problems

Your Task

“Days-From-beginning” is an interesting and useful feature in website design. It shows up how manydays (or even with hours, minutes, and seconds) after an event started. For example, a feature of DaysFrom-Birth shows the number of days after the date of birth. In this assignment, you are going to writea JavaScript program to implement the “Days-From-Birth” feature.

The Concept of Time in JavaScript

In JavaScript a time is defined as a Date Object. Each date object stores its state as a time value, which is aprimitive number that encodes a date as milliseconds since 1 January 1970 00:00:00 UTC. Thus, a datelater than 1 January 1970 00:00:00 UTC will have a positive time value, whereas an earlier date will havea negative time value. On the basis of the common timeline (which we all live on), the distance betweenany two dates can be calculated using their time values in milliseconds. Figure 1 illustrates the concept,where C is a date earlier than 1 January 1970 00:00:00 UTC, and A and B are later with B being furtherthan A.Functional Requirements

Constants and Variables

Within the script section, create constants and variables following professional conventions and initialise them using right values. Some constants and variables have been suggested in the following tables. You should create more when necessary.

Calculation

1. Create a Date object for the date of birth by using the variables created previously.

• Use one prompt function to input the name of user as Figure 2.

CSC1401 Assignment 1 Specification – Days-From-Birth 3

Figure 2: Illustration of the four inputs

• Use another three prompt functions to input the year, month, day of the birth one by one and then transfer them to the Date constructor.

• Mind the order of arguments sent to the constructor;

• Note that month numbers in Date constructor begin at 0 for January (‘1’ entered in prompt function), 1 for February (‘2’ entered in prompt function), and so on;

2. Create a Date object for the current time.

• No arguments need to be supplied to the constructor.

3. Calculate the difference between the current time and the birth time (assume it is the startingtime 0:00:00 a.m. on the Date of birth):

• Use the getTime() member function to get a Date object’s time value in milliseconds

• Deduct the time value of current time by using the value of event time.

4. Calculate the number of days from the birth:

• Divide the time value difference by the number of milliseconds in a day.

• Use the Math.floor() function to reduce the result number to an integer.Presentation

Figure 3 shows a sample output when running the “Days-From-Birth” program. Note that

 the information should be displayed using the alert() function;

CSC1401 Assignment 1 Specification – Days-From-Birth 4

 wherever possible you should use variables in expressions instead of explicit values (e.g., literalsand numbers), for example, using the variable created for the user name instead of a string valueof “Lily”; “XXXX” is the number of days from the date of birth.

Figure 3: Illustration of the Output the layout of output may vary depending on web browsers.

Testing

Test your program by enter your own date of birth to see whether the outcome is correct or not.Non-functional Requirements

Structure of the Source Code

 All code should appear in the script section in the head of the HTML document Do not write any code in the HTML body. All functionality are delivered by JavaScript. In the script order your code as follows:

(a) Constants;(b) Variables and objects (declared and initialised);(c) Other statements.Comments

 You are required to add at least three comments to the source code. Do not comment every single line, instead, comment on blocks of code with a common purpose. Do not simply translate the syntax into English for comments, instead, describe the purpose ofblocks of code.SubmissionWhat You Need to Submit – Two Files

For a complete submission you need to submit two files as specified below.CSC1401 Assignment 1 Specification – Days-From-Birth 5The assignment submission system will accept only the files with extensions specified in this section.1. Statement of Completeness in a file saved in .pdf format in 200-300 of your own words describes: The state of your assignment, such as, any known functionality that has not been implemented,etc. (It is expected that most people will implement all of the functionality of this assignment.) Problems encountered, such as, any problems that you encountered during the assignment workand how you dealt with them; Reflection, such as, any lessons learnt in doing the assignment and suggestions to futureprogramming work.2. The program in a file saved with an .html extension contains the source code implementedfollowing the functional and non-functional requirements.Late Submission and Extension RequestPlease refer to USQ Policy Library - Assessment Procedure for information on the late submission policyand USQ Policy Library - Assessment of Compassionate and Compelling Circumstances Procedure forconsiderable special circumstances in extension request.The Extension Request Form is available on the course’s StudyDesk. Should you need to request anextension please fill the form and email it to the Course Examiner with supportive documents (e.g.,medical certificate or endorsement letter from supervisor in workplace) prior to the due date. Please notethat any requests without supportive documents will be declined straight way withoutconsideration.