title: How does one calculate an output-value which needs to be updated from various form-control elements by control-specific calculation-rules?
body: <p>I need some help as I'm fairly new to JavaScript.</p>
  <p>I wish to create a function that calculates a membership fee</p>
  <p>I tried making a function in JavaScript that checks whether only one option has been selected, but I have no idea how to make it so that I can calculate the fee if a user is eligible for more than one or all discounts. There is no current JS for the age condition yet (between 60 and 80) as I am unsure how to do it.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function feeCalc() {
    var ans = document.getElementById("answer");
    if (document.getElementById('medicalCond-yes').checked) {
      ans.value = calculate('medicalCond-yes');
    }
    if (document.getElementById('empstatus-yes').checked) {
      ans.value = calculate('empstatus-yes');
    }
    if (document.getElementById('empstatus-no').checked) {
      ans.value = calculate('empstatus-no');
    }
    if (document.getElementById('medicalCond-no').checked) {
      ans.value = calculate('medicalCond-no');
    }
  }
  
  function calculate(action) {
    var standardRate = 10;
    var ageRate = 0.1;
    var medicalRate = 0.4;
    var unemployedRate = 0.3;
    var result;
    switch (action) {
      case 'medicalcond-yes':
        discount = (standardRate * studentRate);
        result = standardRate - discount;
        break;
  
      case 'empstatus-yes':
        discount = (standardRate * unemployedRate);
        result = standardRate - discount;
        break;
  
      case 'empstatus-no':
        result = standardRate;
        break;
  
      case 'medicalcond-no':
        result = standardRate;
        break;
    }
    return result;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="form"&gt;
    &lt;label&gt;
      Age
    &lt;/label&gt;
    &lt;input type="range" value="50" min="1" max="100" class="slider" id="age"/&gt;
  &lt;/div&gt;
  
  &lt;div class="form"&gt;
    &lt;label&gt;
      Do you have any long-term medical conditions
      that can affect daily life
    &lt;/label&gt;
    &lt;br/&gt;
    &lt;input type="radio" name="status" value="yes" id="medicalCond-yes"/&gt;Yes
    &lt;input type="radio" name="status" value="no" id="medicalCond-no"/&gt;No
  &lt;/div&gt;
  
  &lt;div class="form"&gt;
    &lt;label&gt;
      Are you currently employed?
    &lt;/label&gt;
    &lt;br/&gt;
    &lt;input type="radio" name="empstatus" value="yes" id="empstatus-yes"/&gt;Yes
    &lt;input type="radio" name="empstatus" value="no" id="empstatus-no"/&gt;No
  &lt;/div&gt;
  
  &lt;div class="form"&gt;
    &lt;label&gt;
      Membership Fee
    &lt;/label&gt;
    &lt;br/&gt;
    Total Fee:
    &lt;input type="text" id="answer" readonly/&gt;
    &lt;input type="button" value="Calculate" onclick="feeCalc()"/&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>