HTML and CSS Reference
In-Depth Information
Exercises
1. Create a
circle
object with the
Object()
constructor and a method that will cal-
culate its circumference.
2. Write a function that will create a
clock
object.
a. It will have three properties:
seconds
,
minutes
, and
hours
.
b. Write two methods:
setTime()
to set the current time and
displayTime()
to
display the time.
c. The user will be prompted to select either a.m./p.m., or military time. The
value he or she chooses will be passed as an argument to the
displayTime()
method.
3. The output will be either
14:10:26
or
2:10:26 pm
depending on what argument was passed to the
display()
method.
4. The following function acts as a constructor to create an Employee object.
Use this function to create three new employees. Set the properties and print
the employees' names. Add a
phone
property to this function.
<script type="text/javascript">
function Employee(){
var = name;
this.getName = function(){
return this.name;
}
this.setName = function(name){
this.name = name;
};
}
5. Create an object literal called Customer. The Customer will have
properties: a name, gender, photo, and occupation. There will be one method
called
showCustomer()
. The user will be prompted for each of the property val-
ues. Use the
showCustomer()
method to display the data in an HTML table.
6. Using JavaScript prototyping, extend the Employee (Exercise 4). Create two
new subclasses from the Employee: a Salesman and a Manager class. Use a pro-
totype to create a salary property for the new employees (
setSalary
,
getSalary
),
and a
setRaise()
method to add 15 percent to the salary. Check to see if each of
the new Employees is an instance of the Employee class.