Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="w3-container" >
  <form>
    <label for="input1">Genotype 1:</label>
    <input type="text" autofocus id="input1"/><br/>
    <label for="input1">Genotype 2:</label>
    <input type="text" id="input2"/><br/>
    <input type="submit" value="Calculate"/>
  </form>
  <hr class="result"/>
  <table id="result_table" class="result"></table>
  <hr class="result"/>
  <div id="result_phenotype" class="result"></div>
  <div id="result_genotype" class="result"></div>
</div>
              
            
!

CSS

              
                /* The following code was inspired from from W3.CSS (www.w3schools.com/w3css) 4.15 December 2020 by Jan Egil and Borge Refsnes. Thanks to them.*/

table, th, td {
  border: 1px solid black;
}

.result {
  display: none;
}

th,td {
  width: 100px
}

tr {
  height: 50px
}

table {
  border-collapse: collapse;
  text-align: center;
}

/* Extract from normalize.css by Nicolas Gallagher and Jonathan Neal git.io/normalize */

body,html{font-family:Verdana,sans-serif;font-size:16px;line-height:1.5}html{overflow-x:hidden}h1{font-size:36px}h2{font-size:30px}h3{font-size:24px}h4{font-size:20px}h5{font-size:18px}h6{font-size:16px}h1,h2,h3,h4,h5,h6{font-family:Helvetica,"Segoe UI",Arial,sans-serif;font-weight:400;margin:10px 0}hr{border:0;border-top:1px solid #eee;margin:20px 0}
              
            
!

JS

              
                $("form").submit((event) => {
  event.preventDefault();
  const input1 = $("#input1").val().split("");
  const input2 = $("#input2").val().split("");
  
  if (input1.length !== input2.length || input1.length % 2 !== 0 || input1.length === 0 || _.toLower(input1) !== _.toLower(input2)) {
    error();
    return;
  }
  
  const length = input1.length;
  
  for (var i = 0; i < length; i += 2) {
    if (_.toLower(input1[i]) !== _.toLower(input1[i+1])) {
      error();
      return;
    }
  }
  
  $("#result_table").html(`
    <tr class="titles">
      <td>&nbsp;</td>
    </tr>
  `);
  $("#result_genotype").html(`
    <h3>Genotype results:</h3>
  `);
  $("#result_phenotype").html(`
    <h3>Phenotype results:</h3>
  `);
  var group1 = groups(input1);
  var group2 = groups(input2);
  var genotype_sumation = new Map();
  var phenotype_sumation = new Map();
  var sumation_total = 0;
  
  for (var i = 0; i < group1.length; i++) {
    $("tr.titles").append(`<th>${group1[i]}</th>`);
  }
  
  for (var i = 0; i < group2.length; i++) {
    let row = "<tr>";
    row += `<th>${group2[i]}</th>`;
    const alleles2 = group2[i].split("");
    for (var j = 0; j < group1.length; j++) {
      const alleles1 = group1[j].split("");
      row += "<td>"
      var cell = "";
      var phenotype = "";
      for (var k = 0; k < alleles1.length; k++) {
        if (_.toUpper(alleles2[k]) === alleles2[k]) {
          phenotype += alleles2[k];
          cell += alleles2[k];
          cell += alleles1[k];
        } else {
          phenotype += alleles1[k];
          cell += alleles1[k];
          cell += alleles2[k];
        }
      }

      if (phenotype_sumation.has(phenotype)) {
        phenotype_sumation.set(phenotype, phenotype_sumation.get(phenotype) + 1);
      } else {
        phenotype_sumation.set(phenotype, 1);
      }

      if (genotype_sumation.has(cell)) {
        genotype_sumation.set(cell, genotype_sumation.get(cell) + 1);
      } else {
        genotype_sumation.set(cell, 1);
      }
      sumation_total++;
      row += cell;
      row += "</td>";
    }
    row += "</tr>";
    $("#result_table").append(row);
  }
  var sumarr = genotype_sumation[Symbol.iterator]();
  for (const genotype of sumarr) {
    $("#result_genotype").append(`<p>${genotype[0]}: ${genotype[1]} (${100*(genotype[1]/sumation_total)}%)</p>`);
  }
  sumarr = phenotype_sumation[Symbol.iterator]();
  for (const phenotype of sumarr) {
    $("#result_phenotype").append(`<p>${phenotype[0]}: ${phenotype[1]} (${100*(phenotype[1]/sumation_total)}%)</p>`);
  }
  $(".result").show();
});

function groups(arr) {
  var result = [];
  for (var i = 0; i < 2**(arr.length/2); i++) {
    var group = "";
    for (var j = 0; j < arr.length; j+=2) {
      group += arr[j + ((i >> j/2) & 0b1)];
    }
    result.push(group);
  }
  return result;
}

function error() {
  alert("Incorrect format of inputs. Example:\nGenotype 1: AaBB\nGenotype 2: aaBb");
}
              
            
!
999px

Console