Professional Documents
Culture Documents
WP - JavaScriptTest Sem1 2020-21
WP - JavaScriptTest Sem1 2020-21
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!!
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.
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.
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.