-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (32 loc) · 1.07 KB
/
script.js
File metadata and controls
42 lines (32 loc) · 1.07 KB
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
let btn = document.getElementById("addbtn");
let studentData = [];
let studentObj1 = { name: "raghav", age: 12, id: 1 };
let studentObj2 = { name: "soha", age: 13, id: 2 };
let studentObj3 = { name: "tiger", age: 14, id: 3 };
let studentObj4 = { name: "Liger", age: 15, id: 4 };
studentData.push(studentObj1)
studentData.push(studentObj2)
studentData.push(studentObj3)
studentData.push(studentObj4)
console.log(studentData);
btn.addEventListener("click", () => {
let name = prompt("Enter Your Name");
let age = prompt("Enter Your Age");
let id = prompt("Enter You Id");
let newStudent = {name, age, id};
studentData.push(newStudent);
console.log("New data entry", studentData);
updateProfile();
});
function updateProfile() {
let tableBody = document.querySelector("tbody")
tableBody.innerHTML = "";
studentData.forEach((oneObj)=>{
let tableRow = document.createElement("tr")
tableRow.innerHTML = `<td>${oneObj.name}</td>
<td>${oneObj.age}</td>
<td>${oneObj.id}</td>`
tableBody.appendChild(tableRow);
});
}
updateProfile();