JSFiddle - React, Tailwind, and code Playground
by Luis Martin
HTML
<form name="calculator">
<input type="textfield" name="ans" id="ans" value="">
<br>
<input type="button" value="1" >
<input type="button" value="2" >
<input type="button" value="3" >
<input type="button" value="+" >
<br>
<input type="button" value="4" >
<input type="button" value="5" >
<input type="button" value="6" >
<input type="button" value="-" >
<br>
<input type="button" value="7" >
<input type="button" value="8" >
<input type="button" value="9" >
<input type="button" value="*" >
<br>
<input type="button" value="0" >
<input type="reset" value="c">
<input type="button" value="/" >
<input type="button" value="=" >
</form>
JavaScript
$('input[type="button"]').on('click', function(){
if($(this).attr("value") == "="){
$("#ans").val( eval($("#ans").val()));
}else{
document.calculator.ans.value += $(this).attr("value");
}
});