JSFiddle - React, Tailwind, and code Playground
HTML
<label>Width</label><input type="text" id="width" />
<br>
<label>Length</label><input type="text" id="length" />
<br>
<label>Total</label><input type="text" id="total"/>
<button>Calculate</button>
JavaScript
function calculate()
{
//Parse the string value into an integer
var w = parseInt($('#width').val());
var l = parseInt($('#length').val());
var total1 = 2;
var total2 = 3;
//Perform IF
//suggestion to use an If {} Else
if((w * l) > 5)
{
//Set an internal value of total
var total = total1 * (w + l);
//Update the label's value to total
$('#total').val(total);
}
if((w * l) < 5)
{
//Same logic as above
var total = total2 * (w + l);
$('#total').val(total);
}
}
//Simple button event for testing
$('button').click(function()
{
calculate();
});