JSFiddle - React, Tailwind, and code Playground

by HSilvaDaytona

HTML

<h1>
  Assignment 15: "Block Chain"
</h1>
Enter Block Chain data here:
<br>
<input type="text" id="start-node"><br>
<input type="button" value="Validate Blockchain" id="click"><br>
<input type="button" value="Invalidate Blockchain" id="click">
<p id='output1'></p>

JavaScript

//Block Chain implemented as a Doubly LInked List 
var Node = function(_content, previousHash = '') {
    this.next = null;
    this.previous = null;
    this.content = _content;
    this.hash = this.content.toString();
    this.previousHash = previousHash;
  
  }
  
  var List = function() {
    this.head = null;
    this.tail = null;
      this.length = 0;
  }
  
  List.prototype.push = function(_content, previousHash) {
    var node = new Node(_content, previousHash);
  
    if (!this.head) {
      this.head = node;
      this.length++;
    } else {
      var current = this.head;
      while (current.next) {
        current = current.next;
      }
      current.next = node;
      this.length++;
    }
  }
  
  List.prototype.toString = function() {
      var str = "";
      var node = this.head;
  
      while (node != null) {
        str += node.content;
        node = node.next;
      }
      return str;
    }
  //Hash Function converts to a 32 bit integer
  // A more clever approach of :http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method
  //was written and posted by Willsmeiser: http://mediocredeveloper.com/wp/?p=55
  /*function hashCode(str) {
    var hash = 0;
  
    for (let i = 0; i < str.length; i++) {
      var char = str.charCodeAt(i);
      hash = ((hash << 5) - hash) + char;
      hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
  }
  */
  var block = new List();
  block.push('One');
  block.push('Two');
  block.push('Three');
  block.push('Four');
  
  console.log(block);
  /*
  Assignment
  You are going to create your own Blockchain (just like in the video) with only one little difference. He uses an Array to store his Blockchain, you are simply going to do this making the Blockchain a List.
  
  Differences will be;
  
  Block object will need a pointer to next (and previous if implemented doubly which I recommend)
  Your Block will NOT need an index
  Your Block will NOT need a...