Assignment 10b hash V2

by pat spag

HTML

Add password to list
<input type="text" value="password" id="passwordInput" size="8">
<input type="button" value="Submit" onclick="addPassword();">
<br>
Check For Password
<input type="text" value="password" id="passwordCheckInput"size ="8">
<input type="button" value="Submit" onclick="checkPassword();" >

<input type ="button" value="test" onclick="test()">
<div id="output">
</div>


<div id="output2">
</div>

JavaScript

var list;
var password = document.getElementById("passwordInput").value;


//list from assignment 4
//following example video
function linkedList(head, tail, length) { //list Properties 
this.head = null;
this.tail = null;
this.length = 0;
}
function node(id, content, next, last) {//required node properties
this.id =  null;
this.content = content;
this.next = next;
this.last = last;
};

linkedList.prototype.add = function(content) {
// create prototype add function
 id=null;
 if (this.head == null) {
   this.head = new node(id, content, null, null);
   this.length = 1;
   return;
 }
 
 var previousNode = this.head; //creating a tail
 for (var i = 0; i < this.length - 1; i+=1) {
  previousNode = previousNode.next;
 }
 //shifting tail
 var nextNode = new node(null, content, null, previousNode);
 previousNode.next = nextNode;
 this.length += 1;
 }

linkedList.prototype.print = function(){
var display = "";
var currentNode = this.head;
while (currentNode != null) {
  display += currentNode.content + "   ";
  currentNode = currentNode.next;
}
return display;
}

function addNode(){
	var nodeValue = document.getElementById("nodeValue").value;
  list.add(nodeValue);
  document.getElementById("output").innerHTML = list.print(); 
}


var sdbmCode = function(str){
    var hash = 0;
    for (i = 0; i < str.length; i++) {
        char = str.charCodeAt(i);
        hash = char + (hash << 6) + (hash << 16) - hash;
    }
    return hash;
}
function addPassword(password){
	password = document.getElementById("passwordInput").value;
  list = new linkedList();
  var hashedPW = sdbmCode(password);
  var hashedNode = list.add(hashedPW);
  document.getElementById("output").innerHTML = list.print();

}

function checkPassword(passwordToCheck){

	passwordToCheck = document.getElementById("passwordCheckInput").value;
	var checkPasswordHash = sdbmCode(passwordToCheck);
  //document.getElementById("output2").innerHTML = hashToString(checkPasswordHash);
if (list.head.content ===...