-
Notifications
You must be signed in to change notification settings - Fork 0
/
script1.js
66 lines (49 loc) · 1.83 KB
/
script1.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
let students = [];
function addStudent() {
const studentName = document.getElementById('studentName').value;
if (studentName.trim() === '') {
alert('Please enter a valid student name.');
return;
}
const student = {
name: studentName,
attendance: []
};
students.push(student);
updateAttendanceTable();
document.getElementById('studentName').value = '';
}
function markAttendance(index, isPresent) {
const date = new Date();
const time = date.toLocaleTimeString();
const student = students[index];
const attendanceRecord = {
date: date.toLocaleDateString(),
time,
isPresent
};
student.attendance.push(attendanceRecord);
updateAttendanceTable();
}
function updateAttendanceTable() {
const tableBody = document.getElementById('attendanceBody');
tableBody.innerHTML = '';
students.forEach((student, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="txt">${student.name}</td>
<td class="txt"></td>
<td class="txt"></td>
<td ><button id="btnp" class="btn" onclick="markAttendance(${index}, true)">Present</button></td>
<td><button class="btna" onclick="markAttendance(${index}, false)">Absent</button></td>
<td class="txt"></td>
`;
tableBody.appendChild(row);
const lastRecord = student.attendance[student.attendance.length - 1];
if (lastRecord) {
row.children[1].innerText = lastRecord.date;
row.children[2].innerText = lastRecord.time;
row.children[5].innerText = lastRecord.isPresent;
}
});
}