I am taking a web 2 class and am kind of stuck on the last question for the chapter. I am supposed to create 2 new subclasses, a manager and a salesman class. Which is done with no errors. Then I am supposed to use a prototype to create a salary property for the new employees (setSalary, getSalary), and a setRaise() method to add 15 percent to the salary. Then check to see if each of the new employees is an instance of the employee class. It works but does not input the salary? Also does not print the input in the form?
enter code here
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Question 4</title>
<script type="text/javascript">
<!-- <! [CDATA [ // Hiding JavaScript from old browsers
function Employee(empnum, firstname, lastname, hphone)
{
//document.write("<br />" + enum + " " + firstname + " " + lastname + " " + hphone );
// Receiving
// parameters
// Properties
this.empnum = empnum;
this.firstName = firstname;
this.lastName = lastname;
this.priContact = hphone;
this.emp_print = display;// Create methods
}
function display()
{ // Functions to be used as methods
document.write("<tr><td>" + myEmp.empnum + "</td><td>" + myEmp.firstName + "</td><td>" + myEmp.lastName + "</td><td>" + myEmp.priContact + "</td></tr>\n");
//document.write("Employee<br />Employee number: " + myEmp.empnum + "\nFirst name: " + myEmp.firstName + "\nLast name: " + myEmp.lastName + "\n Primary phone:\n " + myEmp.priContact + "<br />" ) ;
}
// ]] > -->8
</script>
</head>
<body>
<script type="text/javascript">
<!-- <! [CDATA [ // Hiding JavaScript from old browsers
document.write("<table border=\"1\">");
document.write("<tr><td>Employee Number</td><td>First Name</td><td>Last Name</td><td>Primary Phone</td></tr>");
//Assign employee number
num = 1;
do
{
nam1 = prompt("Enter First Name: " , "");
nam2 = prompt("Enter Last Name: " , "");
pph = prompt("Enter Phone Number: " , "");
//document.write("<br />" + num + " " + nam1 + " " + nam2 + " " + pph );
myEmp = new Employee(num , nam1, nam2, pph ); // Create new object
num++;
display();
}
while (num <= 3)
document.write("</table>");
// ]] > -->8
function Employee(){
var name;
this.getName = function(){
return this.name;
}
this.setName = function(name){
this.name = name;
}
}
function Salesman() {}
Salesman.prototype = new Employee();
Salesman.prototype.constructor = Salesman;
Salesman.prototype.setSalary = function(salary) {
this.salary = salary;
}
Salesman.prototype.getSalary = function() {
return this.salary;
}
Salesman.prototype.setRaise = function() {
return (this.salary+(this.salary*0.15));
}
function Manager() {}
Manager.prototype = new Employee();
Manager.prototype.constructor = Salesman;
Manager.prototype.setSalary = function(salary) {
this.salary = salary;
}
Manager.prototype.getSalary = function() {
return this.salary;
}
Manager.prototype.setRaise = function() {
return (this.salary+(this.salary*0.15));
}
</script>
</head>
<body bgColor="#EOFFFF">
<script type="text/javascript">
sm1 = new Salesman();
sm1.setSalary(10000);
alert("The raise will be "+sm1.setRaise());
mr1 = new Manager();
mr1.setSalary(134320);
alert("The raise will be "+mr1.setRaise());
if (mr1 instanceof Manager)
{
alert('correct');
}
if (mr1 instanceof Salesman)
{
alert('correct');
}
{ alert('false');
}
</script>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire