Assignment 10
by Jeremy Boss
HTML
<input type="textbox" id="passIn" />
<input type="button" value="Add Password To List" onClick="passInClick();" />
<br/>
<br/>
<input type="textbox" id="passCheckIn"/>
<input type="button" value="Check For Password" onClick="passCheckClick();"/>
<input type="button" value="Clear" onClick="clear();" />
<div id="out"></div>
<div id="out2"></div>
JavaScript
var stored = new aList();
function aNode(val) {
this.input = hash(val);
this.next = null;
this.last = null;
return this;
}
function aList() {
this.length = 0;
this.head = null;
this.tail = null;
}
aList.prototype.add = function(val) {
var bNode = new aNode(val);
if (this.head == null) {
this.head = bNode;
this.length = 1;
return bNode;
}
else if (this.tail == null) {
this.tail = bNode;
this.tail.last = this.head;
this.head.next = this.tail;
this.length = 2;
return bNode;
}
else {
this.tail.next = bNode;
bNode.last = this.tail;
this.tail = bNode;
this.length++;
return bNode;
}
}
var hash = function(z) {
var q = 1;
var r = 0;
var s;
var t;
if (z) {
q = 0;
for (s = z.length - 1; s >= 0; s--) {
t = z.charCodeAt(s);
q = (q << 6 & 268435455) + t + (t << 14);
r = q & 266338304;
q = r !== 0 ? q ^ r >> 21 : q;
}
}
return String(q);
}
aNode.prototype.toString = function() {
return "Node: " + this.input + "<br/>";
}
aList.prototype.print = function() {
var out = "";
var bNode = this.head;
while (bNode != null) {
out += bNode.toString();
bNode = bNode.next;
}
return out;
}
function passInClick() {
var passLoc = document.getElementById("passIn").value;
stored.add(passLoc);
outputList();
}
function outputList() {
document.getElementById("out").innerHTML = stored.print();
}
function clear() {
stored = new aList();
document.getElementById("out2").innerHTML = "";
outputList();
}
function passCheckClick(passLoc) {
pass = document.getElementById("passCheckIn").value;
var verify = hash(passLoc);
var nodeCheck = stored.head;
var result = "";
while (nodeCheck != null) {
if (nodeCheck.input == verify){
result = "Password Found";
document.getElementById("out2").innerHTML = result;
return result;
}
nodeCheck = nodeCheck.next;
}
...