4 Replies Latest reply on Oct 5, 2015 3:53 AM by Test Screen Name

    Flesch-Kincaid Reading Ease in JavaScript




      I'm making a PDF to test students' level of English and as an automated marking aid I would like to give each writing part a Flesch-Kincaid Reading Ease score automatically.


      I have found this website https://www.addedbytes.com/blog/code/flesch-kincaid-function/ which has the Javascript calculations but I need help incorporating it into my form.


      I've added the functions to the Document Javascripts but need it to look at a text field where a student would have typed and then to give the score in a separate text box.


      Is this possible with the code supplied? If so, any help getting it to work would be greatly appreciated.

        • 1. Re: Flesch-Kincaid Reading Ease in JavaScript
          try67 MVP & Adobe Community Professional

          The code in that web-site is not in JavaScript, but in PHP. It's possible

          to convert it to JS, but would require an experienced JS developer. Once

          you've done that using it in a PDF should not be too complicated.

          1 person found this helpful
          • 2. Re: Flesch-Kincaid Reading Ease in JavaScript
            Einspain Level 1

            Thanks for the quick answer.


            That proves I'm not experienced enough with this to tell the difference between Java and PHP.


            Any experienced developers here fancy a challenge? In the meantime I'll Google to see if I can find the code in Java.

            • 3. Re: Flesch-Kincaid Reading Ease in JavaScript
              willdenc Level 1

              function score(text){

                return {

                score: 206.835 - (1.015 * avgWordsSentance(text)) - (84.6 * avgSyllablesWord(text)),

                gradingLevel: gradingLevel(text)





              function gradingLevel(text){

                return ((.39 * avgWordsSentance(text)) + (11.8 * avgSyllablesWord(text)) - 15.59);




              function avgWordsSentance(text){

                var sentences = text.split(/[.!?][ |\n]/g).length;

                var words = text.split(/ /g).length;

                return words / sentences;




              function avgSyllablesWord(text){

                var words = text.split(/ /g);

                var syllables = 0;

                for (var i = 0; i < words.length; i++){

                syllables = syllables + countSyllables(words[i]);


                return syllables / words.length;




              function countSyllables(word){

                word = word.toLowerCase();                                 

                if(word.length <= 3) { return 1; }                            

                word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, ''); 

                word = word.replace(/^y/, '');  

                word = word.replace(/-/g, '');

                if (word.match(/[aeiouy]{1,2}/g))                    

                return word.match(/[aeiouy]{1,2}/g).length; 

                return 1;




              var txt = 'The foregoing warranties by each party are in lieu of all other warranties, express or implied, with respect to this agreement, including but not limited to implied warranties of merchantability and fitness for a particular purpose. Neither party shall have any liability whatsoever for any cover or setoff nor for any indirect, consequential, exemplary, incidental or punitive damages, including lost profits, even if such party has been advised of the possibility of such damages.';




              1 person found this helpful
              • 4. Re: Flesch-Kincaid Reading Ease in JavaScript
                Test Screen Name Most Valuable Participant

                Just a note, because it may be important to you: you also need to know the difference between Java and JavaScript. These are entirely different too, Java isn't an abbreviation of JavaScript. This is especially important if you are looking for training, or paying for a job...