Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

School

of Computing and Information Technology


JavaScript Practice Test
Duration: 2hr 15mins

Your page is designed to calculate the parking charges for customers who park their vehicles in a parking
lot. No vehicle is allowed to stay in the parking lot later than midnight - it will be towed away. That
means your time of entering the parking lot cannot be greater than the time you left the parking lot. For
e.g. If you entered the parking lot at 22 hour2 (10 pm) and left at 10 hours (10 am), it meant you stayed
overnight and this is not allowed. You are required to get the entry time in hours and minutes from the
user along with their vehicle information and calculate the time spent in the lot along with their charges.
You are also required to use CSS to beautify the page.

Instructions: Download the file parking.html from Moodle and complete the following
questions. Once you open the file in Moodle, right-click in the centre of the form and select
‘View Frame Source’. Copy the html code to your editor. Resave the file as
parking+[YOURID#]. All files MUST be uploaded to Moodle before the portal closes. Complete
the JavaScript and CSS requirements.

NB: PLEASE NOTE THE UNIVERSITY POLICY ON PLAGIARISM! ALTHOUGH YOU ARE
NOT RESTRICTED FROM USING SOURCES, ALL WORK MUST BE YOUR OWN. ANY
WORK THAT IS FOUND TO BE PLAGIARISED WILL RESULT IN AN IMMEDIATE
FAILING GRADE!!

QUESTION ONE – Get Information [2 + 2 + 2 + 2 Marks]


Create the function definition for getInfo() that will:

i) accept the information from the user for the vehicle type, licence number, make and
model.
ii) accept the hour (in 24 hour format) and minutes the vehicle entered the parking lot .
iii) convert the values for the entry hours and minutes to integers
iv) validate the entry hours and entry minutes by calling a function validateinfo and
sending the values to be validated.

QUESTION TWO – Validate Input [10 marks]



Create a function validateInfo that will validate the hour vehicle entered the parking lot to be
between 0 and 24.and the minutes field should be between 0 and 60. If the values fall outside
those ranges, generate and store a random value between 0 and 24 for the hour time or
between 0 and 60 for the minutes. The function should store the validated information back
into the form.
QUESTION THREE - Calculating the Total Hours Spent [2 + 4 + 10 + 2 marks]
Create the function definition for Timespent() that will calculate the time spent in the parking
lot for each vehicle. This function should:

i) get the entry hours and the entry minutes from the form and convert to integer, if
required..
ii) get the current system hour and minutes as the leaving time of the vehicle (NB
remember the getHours() and getMinutes() methods)
iii) Find the time spent by using the following algorithm:
a) Compare the minute portion of the entering and the leaving time
if the first is smaller than the second
add 60 to the minute portion of the leaving time
subtract 1 from the hour portion of the leaving time
b) Subtract the hour portions to get totalHours
c) Subtract the minute portions to get totalMinutes
d) If the totalMinutes is greater than one then add 1 to the totalHours field.
e) Return the totalHours as the total time spent.
iv) Call a function calculateCharges (defined in question 4) that will accept the total
time spent and will calculate and return the total charge.
v) Call a function display (defined in question 5) to display the results.

QUESTION FOUR – Finding the Total Charges based on Total Time Spent [ 2 + 12 + 2]
Create a function definition for calculateCharges() that will calculate the charge for the vehicle
based on the time spent in the parking lot.

a) Get the vehicle type from the form


b) Depending on the type of vehicle the rate is as follows:
a. Car: $0.00 per hour for first 3 hours $150 per hour after 3 hours
b. Bus: $100 per hour first 2 hours and $250 per hour after 2 hours
c. Truck: $200 per hour for first hour and $370 per hour after first hour

c) Return the total charges.

QUESTION FIVE – Displaying the information in the Form and in HTML [10 marks]
Create a function display Info that will display the information in the bottom half of the page as
displayed at the end of this page. It will display the licence number, the vehicle type, the
description which comprise of the make and model, time entered, time left, total time spent,
the rounded total hours spent and the total charges.
QUESTION FOUR [3 + 6 + 4]
Ensure that the HTML Content have the following event triggers: -

a) Call your main function whenever the Get Charges field is clicked
b) Call your main function whenever the type of vehicle drop-down list changes its
selections.
c) Call the validate() function whenever the entering hours and minutes fields lose focus.

QUESTION FIVE - CSS [25 marks]


Use CSS to beautify the page and the report.

You might also like