This is my Javascript code. I have been trying to debug this for a week and can not figure out what I have been doing wrong. Please help me understand. I am new at coding.
HTML File
<script type="text/javascript" onload="table()">
function table(puppyPics, pictureDesc, pictureDate){
// var puppyPics =[0,1,2,3,4];
//var pictureDesc = [0,1,2,3,4];
//var pictureDate = [0,1,2,3,4];
var body = document.getElementsByTagName("body")[0];
var tbl= document.createElement("table");
var tblBody = document.createElement("tbody");
for (var i = 0; i < puppyPics.length; i++) {
var row= document.createElement("tr");
var cell= document.createElement("td");
for (var j = 0; j < pictureDesc.length; j++) {
document.createElement("tr");
document.createElement("td");
for (var x = 0; x < pictureDate.length; x++) {
document.createElement("tr");
document.createElement("td");
row.appendChild(cell);
}
tblBody.appendChild(row);
}
tbl.appendChild(tblBody);
body.appendChild(tbl);
tbl.setAttribute("border", "2")
}
}
</script>
External JS File
var puppyPics = new Array();
var pictureDesc = new Array();
var pictureDate = new Array();
puppyPics[0] = "AllTheKids.jpg";
puppyPics[1] = "susie.jpg";
puppyPics[2] = "princess.jpg";
puppyPics[3] = "wicketAndCarlos.jpg";
puppyPics[4] = "wicketAndGeorge.jpg";
pictureDesc[0] = "This is all the new puppies together. They are so cute! I just want to hold them all.";
pictureDesc[1] = "A friend held Susie up so that you can get a good look at her face. She looks just like her mom.";
pictureDesc[2] = "This is Princess, she is the same color as her brother Wicket. She loves to just give kisses to everyone who holds her.";
pictureDesc[3] = "Wicket is a very social puppy. He's not even afraid of Carlos who is my brother's dog.";
pictureDesc[4] = "Finally, here is Wicket and George. I like how they are starting to play together. They will be running around the yard in no time";
pictureDate[0] = "March 10, 2012";
pictureDate[1] = "March 10, 2012";
pictureDate[2] = "March 10, 2012";
pictureDate[3] = "March 15, 2012";
pictureDate[4] = "March 15, 2012";
table?document.write. It doesn't work if you try it after the page is loaded. Use DOM manipulation.tablefunction takes three arguments, then overwrites them immediately. What is the point of accepting them, then?[...]withintable, but you revert tonew Array(); [0]=; [1]=...after the function definition. Why?</script>tag after the function