I'm a new javascript learner. I am currently trying to append a new table to the existing page by the use of a button. The function takes in a list and prints out the number, its squared and cubed value into a table. When I press the button, the old table is deleted and overwritten by the new table. How would I append the new table onto the page? All advice are appreciated. Here is my code
<!DOCTYPE html>
<html lang="en">
<head>
<title>
</title>
<script>
function table(a) {
document.write('<table>');
document.write("<tr><td>Number</td><td>Square</td><td>Cube</td></tr>");
for (var i = 0; i < a.length; i++) {
document.write("<tr><td>" + a[i] + "</td><td>" + Math.pow(a[i], 2) + "</td><td>" + Math.pow(a[i], 3) + "</td></tr>");
}
document.write('</table>')
}
</script>
</head>
<body>
<script>
var list1 = [1, 2, 3, 4, 5, 6];
table(list1);
</script>
<input type="button" onclick="table([7,8,9,10]) " value="dispay table">
<!-- this button removes overwrites the old table-->
</body>
</html>