title: Javascript - Replace lots of if statements
body: <p>I have a a couple of different radio buttons which return an ethnicity and a gender. The script runs inside an internal application so rather than returning "boy", "girl" or "both" I get back 7707330, 7707333, and 7707336. Similar from the ethnicity radio button. </p>
  
  <p>I then need to validate data based on the combonation of ethnicity and gender. This was a pretty simple task but I have ended up with 15 if statements! It all works as it should, but there must be a cleaner solution? </p>
  
  <pre><code>function test(radioResults) {
      var1 = radioResults[0].toString();
      var2 = radioResults[1].toString();
  
      var roll = parseFloat(parent.roll);
  
      if (var2 == '7707330') {
          gender = 'boy';
      }
      if (var2 == '7707333') {
          gender = 'girl';
      }
      if (var2 == '7707336') {
          gender = 'both';
      }
  
      if (var1 == '7707341') {
          maori(gender);
      }
      if (var1 == '7707344') {
          pasifika(gender);
      }
      if (var1 == '7707347') {
          all(gender);
      }
  }
  
  function maori(gender) {
      //Maori 
      if (gender == 'boy') {
          ethnicity = parseFloat(parent.getMBoys);
          validation(ethnicity);
      }
      if (gender == 'girl') {
          ethnicity = parseFloat(parent.getMGirls);
          validation(ethnicity);
      }
      if (gender == 'both') {
          ethnicity = parseFloat(parent.getTotalM);
          validation(ethnicity);
      }
  }
  
  function pasifika(gender) {
      //Pasifika
      if (gender == 'boy') {
          ethnicity = parseFloat(parent.getPBoys);
          validation(ethnicity);
      }
      if (gender == 'girl') {
          ethnicity = parseFloat(parent.getPGirls);
          validation(ethnicity);
      }
      if (gender == 'both') {
          ethnicity = parseFloat(parent.getTotalP);
          validation(ethnicity);
      }
  }
  
  function all(gender) {
      //All
      if (gender == 'boy') {
          ethnicity = parseFloat(parent.getBoys);
          validation(ethnicity);
      }
      if (gender == 'girl') {
          ethnicity = parseFloat(parent.getGirls);
          validation(ethnicity);
      }
      if (gender == 'both') {
          ethnicity = parseFloat(parent.getTotalRoll);
          validation(ethnicity);
      }
  }
  
  function validation(ethnicity) {
  
      percent = ethnicity * 5 / 100;
  
      if (ethnicity - percent &gt; roll || (ethnicity + percent &lt; roll)) {
          parent.document.getElementById('CF_7784443').value = "FAIL";
      } else {
          parent.document.getElementById('CF_7784443').value = "PASS";
      }
  }
  </code></pre>
  
  <p>How would I go about cleaning this up? </p>