Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1>Readability: <span id="readability"></span></h1>
<div class="textWrapper">
  <textarea placeholder="Type here">Type or paste here. Is it easy to read?</textarea>
</div>
              
            
!

CSS

              
                *{
  font-familty:inherit;
  font-size:inherit;
}

body{
  font-family:Garamond,serif;
  font-size:24pt;
  margin:1em;
}

.textWrapper{
  height:80vh;
}

textarea{
  width:100%;
  height:100%;
}

              
            
!

JS

              
                var SENTENCE_SIZE,
    WEIGHT,
    BASE;

SENTENCE_SIZE = 30;
WEIGHT = 1.0430;
BASE = 3.1291;

/**
 * Get the grade level of a given value according to the SMOG formula.
 * More information is available at WikiPedia:
 *
 *   http://en.wikipedia.org/wiki/SMOG
 *
 * @param {Object} counts
 * @param {number} counts.sentence - Number of sentences.
 * @param {number} counts.polysillabicWord - Number of polysillabic words
 *   (three or more syllables).
 * @return {number}
 */

function smog(counts) {
    if (!counts || !counts.sentence) {
        return NaN;
    }

    return WEIGHT * Math.sqrt(
            (counts.polysillabicWord || 0) * (SENTENCE_SIZE / counts.sentence)
        ) + BASE;
}

var area = document.querySelector('textarea');
var readability_el = document.getElementById('readability');

var ages = [
  'Empty',
  'Toddler','Toddler','Toddler', // 1–3
  'Kindergarten', 'Kindergarten', // 4–5
  'First Grade', // 6
  'Second Grade', // 7
  'Third Grade', // 8
  'Fourth Grade', // 9
  'Fifth Grade', // 10
  'Sixth Grade', // 11
  'Seventh Grade', // 12
  'Eighth Grade', // 13
  'Ninth Grade', // 14
  'Tenth Grade', // 15
  'Eleventh grade', // 16
  'Twelfth grade', // 17
  'College', 'College', 'College', 'College', 'College',
  'Grad School &amp; Beyond'
];

var sentence = /[^.!?\s][^.!?]*(?:[.!?](?!['"]?\s|$)[^.!?]*)*[.!?]?['"]?(?=\s|$)/g;
var word = /\w+/g;
var syllable = /[aeiouy]+[^$e(,.:;!?)]/g;

var displayReadability = area.oninput = function(){
  var sentences = area.value.match(sentence);
  var words = area.value.match(word);
  var polysillabicWord = 0;
  for(var i=0; i<words.length; i++){
    var wordSyllables = words[i].match(syllable);
    if(wordSyllables !== null && wordSyllables.length >= 3){
      polysillabicWord++;
    }
  }
  var counts = {
    word:words.length,
    sentence:sentences.length,
    polysillabicWord:polysillabicWord
  };
  var readability = smog(counts);
  readability = Math.ceil(readability);
  readability = Math.max(0,readability);
  readability = Math.min(readability,ages.length-1);
  readability_el.innerHTML = readability + ' years ('+ages[readability]+')';
}

displayReadability();

              
            
!
999px

Console