Problem with my problem

<!DOCTYPE  html>
<html>
<head>
<title>Project 2</title>
<meta charset="utf-8">
<script>
	var subcnt = 0;
	var data = new Array();
	function addRow(){
		var unit = document.getElementById('unit').value;
	               data.push(parseInt(document.getElementById('unit').value));
	               document.getElementById('unit').value;
	               submitOk = true;

	              if(unit.length ==  ''){
	              	alert("What the Unit?");
	              	return false;
	              }

	              var des = document.getElementById('sub').value;
	               if(sub.length == ''){
	               	alert("What is the Subject?");
	               	submitOk = false;
	               }

	              var des = document.getElementById('des').value;
	               if(des.length == ''){
	               	alert("What is the Description?");
	               	submitOk = false;
	               } 

	              if(submitOk == true){
	              	var str = '';

	              	var table  = document.getElementByTagName('table')[0];

	              	var newRow = table.insertRow(table.rows.length/2+1);
	              	
	              	var cel1 = newRow.insertCell(0);
	              	var cel1 = newRow.insertCell(1);
	              	var cel1 = newRow.insertCell(2);

	              	cel1.innerHTML = sub;
	              	cel2.innerHTML = des;
	              	cel3.innerHTML = unit;

	              	var totalunits = sum(data);

	              	str = '<br>' + "Total Unit: " +totalunits+'<br>'+"Number of Subject: " + subcnt; document.getElementById("demo").innerHTML = str;
                  }
	              	alert("add = " + submitOk)

	              }
	    function sum(arr){
	    	var total=0;
	    for(var i = 0; i < arr.length; i++){
	    	if(i != null){
	    		total+=Number(arr[i]);
	    	}
	    	subcnt+=1;
	    	return total;
	        }	
	    }
	              


</script>
</head>
<body bgcolor='#FF00FF'>
	<center>
	<h1><i>P2</i></h1>
	<br>
	<br>
	Subject Code: <input type="text" onfocus="this.value=''" name="sub" /><br/><br/>
	Description: <input type="text" onfocus="this.value=''" name="sub" /><br/><br/>
	Units: <input type="number" onfocus="this.value=''" name="sub" /><br/><br/>
	<button onclick="addRow();">Add Row</button><br/><br/>
	<p id ="demo"></p><br/><br/>
	<table border = "1">
		<tr>
			    <th>Subject Code</th>
	    		<th>Description</th>
	    	    <th>Units</th>
	    </tr>
	    </table>

	    <footer><a><i><b>By: Kurt Exmundo</b></i></a></footer></center>
	    </body>
	    </html>

i cant seem to run my program and I need this in 2 hours

You cannot take an element if you have not created it first. You also have to put your script tag at the end of all your visual content on your page.

which of the element are your refering to?

Hi,
Although I’m Javascript beginner,I think it refers to “unit” that not declared in HTML.
Also “sub” is not declared in the HTML file.