JSFiddle - React, Tailwind, and code Playground

by Erik East

HTML

<h2>Module 06</h2>
<h3>Assignment 1</h3>
<div id="sCount">
    <h1>Tower of Hanoi Calculator</h1>
    <p>This program is not designed to solve a Tower of Hanoi puzzle. It is designed to calculate the minimum number of moves necessary to be able to solve a Tower of Hanoi puzzle, based on how many disks the user puts into the calculator.<p/>
<p>The calculator uses an algorithmic equation, taken from the logics of how to solve the puzzle, and processed through <b>Mathematical Induction</b> and <b>Recurrence Relations</b>.<br/>
The follwing euqation is used to calculate this minimum number of moves:</p>
<h1>2<sup>n</sup> - 1</h1>
    
<input type='text' id='stuffing' size='20' onkeypress='captureEnter(event);'><br/>
</div>   
<div id="display" >

</div>

JavaScript

function captureEnter(e){
        if(e.keyCode === 13){
            //call function
            valueCheck();
        }
        return false;
}

    //document.getElementById('stuffing').value;
    
function valueCheck (){
var diskNum = document.getElementById('stuffing').value;
    if (!isNaN(parseInt(diskNum))){
        hanoiCalc(diskNum);
    }
}

function hanoiCalc(diskNum){
    var moves = Math.pow(2, diskNum) - 1;
    document.getElementById('display').innerHTML = 'Number of Moves: -- ' + moves;
}