Word counter tools in asp.net MVC using c#

Word counter tools in asp.net MVC using c#

In action

public ActionResult WordCounter()
        {
            return View();
        }

In cshtml page

<h1>Word Counter tools</h1>

<p>To use this Word Count Checker, Copy and paste your content into the box below, and then state back and watch as Word Count Checker will run a real-time output.</p>

<div class="word-count">
    <div class="relative">
        <textarea placeholder="Enter text here for words count." id="textCount" class="textarea"></textarea>
    </div>
    <div class="col-md-12 text_val_wrap color_808080" style="padding: 0px;">
    <div class="text_val">Total Words (<span id="wc">0</span>)</div>
    <div class="text_val">Total Characters (<span id="cc">0</span>)</div>
</div>
</div>
<div class="line"></div>
<script>
    (function ($) {
        var wordCounter = {
            init: function () {
                this.DOM();
                this.events();
            },
            DOM: function () {
                this.textbox = $("#textCount");
                this.wordCount = $("#wc");
                this.charCount = $("#cc");
            },
            events: function () {
                this.textbox.on("input", this.count.bind(this));
            },
            count: function () {
                var words = this.textbox.val().split(" "),
                    chars = this.textbox.val();

                //DELETE EMPTY STRINGS
                for (var i = 0; i < words.length; i++) {
                    while (words[i] === "") {
                        words.splice(i, 1);
                    }
                }
                //COUNT WORDS
                if (words.length === 1) {
                    this.wordCount.text(words.length + " word");
                } else {
                    this.wordCount.text(words.length + " words");
                }
                //COUNT CHARACTERS
                if (chars.length < 0) {
                    words = [];
                } else if (chars.length === 1) {
                    this.charCount.text(chars.length + " character");
                } else {
                    this.charCount.text(chars.length + " characters");
                }
            }
        }
        wordCounter.init();
    }(jQuery));
</script>

2020-06-11