-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployee.js
82 lines (75 loc) · 1.8 KB
/
employee.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// employee
class Employee {
constructor(
firstName = 'John',
lastName = 'Doe',
designation = 'Trainee',
dateOfJoining = null,
salary = 0,
email,
mobile
) {
this.firstName = firstName;
this.lastName = lastName;
this.designation = designation;
this.dateOfJoining = dateOfJoining;
this.salary = salary;
this.email = email;
this.mobile = mobile;
}
}
var employees = [];
function addEmployee() {
let firstName = document.querySelector('#first-name').value;
let lastName = document.querySelector('#last-name').value;
let designation = document.querySelector('#designation').value;
let dateOfJoining = document.querySelector('#date-of-joining').value;
let salary = document.querySelector('#salary').value;
let email = document.querySelector('#email').value;
let mobile = document.querySelector('#mobile').value;
const emp = new Employee(
firstName,
lastName,
designation,
dateOfJoining,
salary,
email,
mobile
);
employees.push(emp);
}
function showEmployee() {
var view = document.querySelector('#view');
var eTable = '';
var i = 0,
j = 0;
for (let employee of employees) {
eTable += `<table>
<caption>Employee #${++i}</caption>
<tr>
<th>Full Name</th>
<td>${employee.firstName + ' ' + employee.lastName}</td>
</tr>
<tr>
<th>Designation</th>
<td>${employee.designation}</td>
</tr>
<tr>
<th>Date of Joining</th>
<td>${employee.dateOfJoining}</td>
</tr>
<tr>
<th>Salary</th>
<td>${employee.salary}</td>
</tr>
<th>Email</th>
<td>${employee.email}</td>
</tr>
<tr>
<th>Mobile</th>
<td>${employee.mobile}</td>
</tr>
`;
}
view.innerHTML = eTable;
}