I've been trying to get around, howto add my Student object, to my array. Once I got that fixed, I tried to display what's inside the array, onto a table, in a html file.
Student Object:
var Student = function (fullName, email, phone, category, groupID) {
this.fullName = fullName;
this.email = email;
this.phone = phone;
this.category = category;
this.groupID = groupID;
};
studentArray:
var studentArray = new Array(Student);
makeTable function:
function makeTable() {
var student1 = new Student("Waw","waaw","awaw","waaw","waaw");
studentArray.push(student1);
document.write("<table>");
document.write("<thead><tr><th>Full Name</th><th>Email</th><th>Phone</th><th>Category</th><th>Group</th></tr></thead>");
document.write("<tbody>");
for(i = 0; i < studentArray.length; i++){
document.write("<tr><td>" + studentArray[i].fullName +"</td><td>" + studentArray[i].email +"</td><td>" + studentArray[i].phone +"</td><td>" + studentArray[i].category +"</td><td>" + studentArray[i].groupID +"</td></tr>");
}
document.write("</tbody>");
document.write("</table>");
}
Html File:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../script/scripts.js" type="text/javascript"></script>
</head>
<body>
<script>
makeTable();
</script>
</body>
</html>
Output:
https://i.stack.imgur.com/j5cnN.png
I regulary program in Java normally, however, only reason I could imagine this not working, is as if I made the array the wrong way, or my array still is empty, after inserting student1 into studentArray.
Thanks in advance.