Singly-Linked List master

A singly-linked list, with extra function to add new links/tails.

by Prasad Gavande

HTML

<h1>Linked List</h1>
<p>Give your pennance (max 20 characters):</p><br/>

<p id="demo"></p>
<input type='text' id='number' size='20'onkeypress='captureEnter(event);'><br/>

JavaScript

// Define the link object
function Link(_id, _value, _next) {

    this.id = _id; // The id of the current link
    this.value = _value; // The value stored 
    this.next = _next; // a pointer to the next link, this is 0 if it is the last link in the chain
}

Link.prototype.theScribe = function () {
     return "" + this.value +
        " --Location: " + this.id +
        " - Points To: " + this.next + "<br/>";
};


// Define the Chain object
function Chain(_firstValue) { // We will define the chain with the first link defined
    this.length = 1;
    // I like to keep track of the first link, not really necessary
    this.head = new Link(1, _firstValue, null);
    // I need a place to store this links - an array will work fine and is pretty much one of the few options you have in JS
    this.linkStorage = [];
    // Oh yea - since we aren't creating an empty Chain - let's fill in that first value    
    this.linkStorage.push(this.head);

}

Chain.prototype.lastLink = function () {
    // A function to find the last link in the chain
    return this.linkStorage[this.length - 1];
};

Chain.prototype.Finder = function(eyeDee){
        for(var i=0; i < this.length; i++){
         if(eyeDee == this.linkStorage[i].id){
             return this.linkStorage[i];
			 }
        }
};

Chain.prototype.Push = function (_linkValue) {
    // A function to add a link to the chain
    this.length++;
    var Zelda = new Link(this.length, _linkValue, null);
    this.linkStorage.push(Zelda);
    this.linkStorage[this.length - 2].next = this.length;
    console.log("Pushed value: " + Zelda.value);
    return Zelda;
};

Chain.prototype.Pop = function (_linkValue) {
   // alert(this.head.value);
    var hold = this.head;
    var thenext = this.Finder(this.head.next); //set thenext to be the NODE with ID that head points to
    this.head = thenext;
    console.log("the next: " + thenext.value + " "  + thenext.id );
    console.log("Popped value: " + hold.value);
    return...