JSFiddle - React, Tailwind, and code Playground

by arosado417

HTML

<input type="button" id="CreateList" value="Create List" onClick="createList();" />
    <br /><br />
    <input id="a" Value="ABCDE" />
    <input type="button" id="AddNode" value="Add Node to List" onClick="addNode();" />
<div id="output">

</div>

JavaScript

function createList() {
            var value = document.getElementById("a").value;
            list = new List(value);
            document.getElementById("output").innerHTML = list.print();
        }


        function addNode() {
            var value = document.getElementById("a").value;
            list.addNode(value,list.last);
            document.getElementById("output").innerHTML = list.print();
        }



        function Node(_value, _last) {
            // This is a implementation of a Doubly Linked List
            this.value = _value;
            this.last = _last; 
            this.next = null; 
            return this;
        }

        Node.prototype.asString = function () {
           this.value + "<br/>";
        }


        // Define the List object
        function List(_value) { 
            this.length = 1;
            this.head = new Node(_value, null); 
        }

        

       
        List.prototype.print = function () {
            var s = "";
            var node = this.head;

            while (node != null) {
                s += node.asString();
                node = node.next;
            }

            return s;
        }