i have a function to create a schedule i have a class schedule then an array which stores the objects created but when i try displaying the objects in a table i get undefined
const mySchedules=[];
class Schedule {
constructor(name, subject, time, day) {
this.name = name;
this.subject = subject;
this.time = time;
this.day = day;
}
}
function create() {
let
name = document.getElementById("name").value,
subject = document.getElementById("subject").value,
time = document.getElementById("time").value,
day = document.getElementById("day").value,
table = document.getElementById("table")
mySchedules.push(new Schedule(name, subject, time, day))
//create object
let obj = new Schedule();
// Create Row
let row = `<tr>
<td>${obj.name}</td>
<td>${obj.subject}</td>
<td>${obj.time}</td>
<td>${obj.day}</td>
</tr>`;
table.insertAdjacentHTML("beforeend", row);
}
let obj = new Schedule();<= no arguments are given to the constructor. Why do you even need that variable.objshould be set to the schedule you created and appended to the array. Not a new empty onelet obj = new Schedule();because it is empty, instead you can loop throughmySchedulesarray