JSFiddle - React, Tailwind, and code Playground

HTML

<form>
    <input type="text" id="input" value="2"/><br />
<input type="button" value="a+a" id="math1" />
    <input type="button" value="a^2" id="math2" />
<input type="button" value="a^3" id="math3" /><br />
    <input type="text" id="output"/>
</form>

JavaScript

$input = $('#input');
$output = $('#output');
$input.bind("keyup input paste", update);

function update() {
    $output.val(currentFormula(parseFloat($input.val())));
}

$('#math1').click(function () {currentFormula = math1; update();});
$('#math2').click(function () {currentFormula = math2; update();});
$('#math3').click(function () {currentFormula = math3; update();});
    
function math1 (a) {return a+a;}
function math2 (a) {return a*a;}
function math3 (a) {return a*a*a;}

currentFormula = math1;