Problem with my problem

<!DOCTYPE  html>
<title>Project 2</title>
<meta charset="utf-8">
	var subcnt = 0;
	var data = new Array();
	function addRow(){
		var unit = 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){
	    	return total;

<body bgcolor='#FF00FF'>
	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">
			    <th>Subject Code</th>

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

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?

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.