JSFiddle - React, Tailwind, and code Playground

by Erik East

HTML

<h2>Module 4</h2>
<h3>Assignment 01</h3>

<p id='theInfo'></p>

JavaScript

var Node = function(_content) {
    this.next = null;
    this.last = null;
    this.content = _content;
  }//var Node = function _content

  var Stack = function() {
    this.head = null;
    this.top = null;
    this.push = function(_content) {

      if (this.head == null) {
        this.head = new Node(_content);
        this.top = this.head;
        return this;
      }//if this.head is equal to null
      
      var addedNode = new Node(_content);
      addedNode.last = this.top;
      this.top.next = addedNode;
      this.top = addedNode;
      return this;
    }//this.push equals function _content

    this.pop = function() {
      if (this.head == null) {
        return null;
      }//if this.head is equal to null

      var n = this.top.content;

      if(this.top == this.head){
        this.head = null;
        this.top = null;
        return n;
      }//if this.top is equal to this.head
      else{
        this.top = this.top.last;
        this.top.next = null;
        return n;
      }//else
    }//this.pop is equal to function()

    this.toString = function() {
      var str = "";
      var node = this.head;
      if (this.head == null){
        str = "Empty stack";
      }//if this.head is equal to null
      while (node != null) {
        str += node.content + "&nbsp";
        node = node.next;
      }//while node is not equal to null
      return str;
    }//this.toString equals function
    
    this.countElements = function() {
      var count = 0;
      var node = this.head;
      while (node != null) {
        node = node.next;
        count= count+1;
      }//while node is not equal to null
      return count;
    }//this.countElements = function
  }//var Stack equals function
  var startOverButton = '<input type="button" value="Start Over" onClick="startOver();" />';
  var runCalculatorButton = '<input type="textbox" id="calculate" style="width: 10px;" value="+" /><input type="button" value="Calculate" onClick="runCalculator();" />';
  var...