Martha's COIN 70b JavaScript Test Pages

Calculator

Results

Value:
Action: Double Square
Result:

SCRIPT

function calculate(form, callingField) {
     if (callingField == "result") { // is the calling field the "result" field?
          // is the "square" radio button checked?
          if (form.action[1].checked) form.entry.value = Math.sqrt(form.result.value);
          else form.entry.value = form.result.value / 2;
     }
     else {
              if (form.action[1].checked) form.result.value = form.entry.value * form.entry.value;
              else form.result.value = form.entry.value * 2;
    }
}