Trying to cleanly remove part of a JavaScript code

I want to strip out the err alert notification portion from the code.

Full Code: https://jsfiddle.net/uhgpq6sr/

<script type="text/javascript">

fob = document.forms[0];

function calc()
{
	n1 = fob.num1.value;
	n2 = fob.num2.value;
	d1 = fob.den1.value;
	d2 = fob.den2.value;
	
	err = false;
	
	if (n1 == "" || d1 == "")
	{
		err=true;
		alert("Both values on the left side of the equation need to have values.");
	}
	
	if (n2 == "" && d2 == "")
	{
		err=true;
		alert("Only one of the values on the right side of the equation can have a value.");
	}
	
	if (!err)
	{
		if (n2 == "")
		{
			fob.num2.value = Math.round(d2 * n1 / d1);
		}
		
		if (d2 == "")
		{
			fob.den2.value = Math.round(d1 * n2 / n1);
		}
	}
}

</script>

Did I do this right?

Did I remove everything I was supposed to?

code: https://jsfiddle.net/mgf3s9od/


<script type="text/javascript">

fob = document.forms[0];

function calc()
{
	n1 = fob.num1.value;
	n2 = fob.num2.value;
	d1 = fob.den1.value;
	d2 = fob.den2.value;
	
	{
		if (n2 == "")
		{
			fob.num2.value = Math.round(d2 * n1 / d1);
		}
		
		if (d2 == "")
		{
			fob.den2.value = Math.round(d1 * n2 / n1);
		}
	}
}

</script>

I believe these 2 still need to be removed, but I don’t know how.

code: https://jsfiddle.net/mgf3s9od/

n1 = fob.num1.value;
d1 = fob.den1.value;

How would I remove them from this part?

The n1, and d1

	{
		if (n2 == "")
		{
			fob.num2.value = Math.round(d2 * n1 / d1);
		}
		
		if (d2 == "")
		{
			fob.den2.value = Math.round(d1 * n2 / n1);
		}
	}
}

I don’t think I want to be doing that, so then,

The above code is correct the way it is.

code: https://jsfiddle.net/mgf3s9od/

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.