JSFiddle - React, Tailwind, and code Playground

by Erik East

HTML

<h2>Module 06</h2>
<h3>Assignment 7</h3>
<p>Enter a number: <input type="textbox" id="theNumber" style="width: 25px;"/></p>
<p><input type="button" value="Run" onClick="displayInfo();" /></p>
<p id='theInfo'></p>

JavaScript

var valueToProcess = '';
var iteration = 0;

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

var Stack = function() {
  this.front = null;
  this.back = null;

  this.push = function(_content) {
    if (this.front == null) {
      this.front = new Node(_content);
      this.back = this.front;
      return this;
}//if front == null

var addedNode = new Node(_content);
addedNode.previous = this.back;
this.back.next = addedNode;
this.back = addedNode;
return this;
}//function

this.removeFront = function() {
  if (this.front == null) {
    return null;
}//front == null

var contentRemoved = this.front.content;

if(this.back == this.front){
  this.front = null;
  this.back = null;
  return contentRemoved;
}//if
else{
  this.front = this.front.next;
  this.front.previous = null;  
  return contentRemoved;
}//else
}//removefront function

this.removeBack = function() {
  if (this.front == null) {
    return null;
}//if

var contentRemoved = this.back.content;

if(this.back == this.front){
  this.front = null;
  this.back = null;
  return contentRemoved;
}//if
else{
  this.back = this.back.previous;
  this.back.next = null;
  return contentRemoved;
}//else
}//removeback function


this.toString = function() {
  var str = "";
  var node = this.front;
  if (this.front == null){
    str = "&nbsp;";
}//if
while (node != null) {
  str += node.content + "&nbsp";
  node = node.next;
}//while
return str;
}//tostring function

this.countIt = function() {
  var count = 0;
  var node = this.front;
  while (node != null) {
    node = node.next;
    count= count+1;
}//while
return count;
}//count function
}//Stack function

function theSolution(x,cupFrom,cupTo,cupUtility) {
  if (x > 1){
    theSolution(x-1,cupFrom,cupUtility,cupTo);
    theSolution(1,cupFrom,cupTo,"");
    theSolution(x-1,cupUtility,cupTo,cupFrom);
}//if x>1
if (x == 1){
  moveXtoY(cupFrom,cupTo);
}//if x is 1
}//recursive function

function...