JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="a">write some words (up to 10)</textarea>
<br />
<input id="finalcount" value="0" disabled />

JavaScript

$(function() {
    var maxWords = 10;
    var wordCounts = {};
    $("#a").keyup(function() {
        var matches = this.value.match(/\b/g);
        wordCounts[this.id] = matches ? matches.length / 2 : 0;
        var finalCount = 0;
        $.each(wordCounts, function(k, v) {
            finalCount += v;
        });
        $('#finalcount').val('Words: ' + finalCount);
        if(finalCount > maxWords){
            $("#a").val(a.value.slice(0,-2));
        };
    }).keyup();
});