Assignment 10
by aren_anderson
HTML
Add Password to List <input type="text" id="password" value="">
<input type="button" value="Submit" id="addpass" onclick="addPass();">
<br>
<br> Check For Password <input type="textbox" id="check">
<input type="button" value="Submit" id="checklist" onclick="checkList();">
<p id="output1"></p>
JavaScript
var myList = new LinkedList();
function LinkedList() {
this.head = null;
// this.tail = null;
this.length = 0;
function Node(content) {
this.content = null;
//this.last = null;
this.next = null;
// return this;
}
LinkedList.prototype.add = function(content) {
var node = new Node();
node.content = content;
if (!this.head) {
this.head = node;
this.length++;
//return node;
} else {
var message = this.head;
while (message.next) {
message = message.next;
}
message.next = node;
this.length++;
}
}
LinkedList.prototype.check = function(content) {
var message = this.head;
while (message) {
if (message.content == content) {
document.getElementById("output1").innerHTML = "Password found";
return true;
} else {
document.getElementById("output1").innerHTML = "Password not found";
return false;
}
message = message.next;
}
}
//var list = new LinkedList();
}
function addPass() {
var input = document.getElementById("password").value;
myList.add(hashCode(input));
}
function checkList() {
var checkMe = document.getElementById("check").value;
myList.check(hashCode(checkMe));
}
function hashCode(str) {
var hash = 0;
//if (this.length == 0) return hash;
for (var i = 0; i < str.length; i++) {
var char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return hash;
}