Assignment10
by zazagalaxy
HTML
<h1>Assignment 10</h1>
<input type = 'text' id = 'v' size = 15 >
<button id = 'store' onclick = 'add()'>Store Password</button>
<br/>
<br/>
<input type = 'text' id = 'check' size = 15 >
<button id = 'checkpw' onclick = 'checkPass()'>Check Password</button>
<p id = 'output'>
Hashed user input:
</p>
<p id = 'output1'></p>
<p id = 'output2' font = 'purple'></p>
JavaScript
//create node
function Node(content) {
content = document.getElementById('v').value;
this.next = null;
this.prev = null;
this.key = hashPw(content);
return this;
}
//create a new linked list
function LinkedList(content) {
this.head = null;
this.tail = null;
this.length = 0;
return this;
}
//Push function that calls Add function
LinkedList.prototype.push = function(content) {
this.add(content);
}
//add node to top of list (put plate on top of stack)
LinkedList.prototype.add = function(content) {
var node = new Node();
node.content = content;
if (this.head == null) {
this.head = node;
this.length = 1;
return node;
}
if (this.tail == null) {
this.tail = node;
this.tail.prev = this.head;
this.head.next = this.tail;
this.length++;
return node;
}
this.tail.next = node;
node.prev = this.tail;
this.tail = node;
this.length++;
return node;
}
LinkedList.prototype.print = function() {
if (this.head == null) return "Empty List";
var string = "";
var node = this.head;
while (node != null) {
string += node.key + '</br>';
node = node.next;
}
return string;
}
//creates a new linked list named 'aList'
var aList = new LinkedList();
//used to get user input and then passed the the ll.proto.add function
function add() {
var content = document.getElementById('v').value;
aList.push(content);
document.getElementById('output1').innerHTML = aList.print();
document.getElementById('v').value = '';
document.getElementById('v').focus();
}
//takes input from Node function and hashes it
function hashPw (content) {
var...