A program that will ask the user to give a string or a sentence and then the program will count the number of consonants and vowels using JavaScript programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

=================================================



Want to support my channel?

GCash Account

Jake Pomperada

09173084360



Paypal

https://paypal.me/jakerpomperada



Patreon

https://www.patreon.com/jakerpomperada



Thank you very much for your support.
Program Listing
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Count Consonants and Vowels Using JavaScript</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        body {
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #cacaca;
            color: #04181F;
            font-family: sans-serif;
            font-size: 90%;
        }
        main {
            padding: 30px;
            border-radius: 10px;
            background-color: #f1f1f1;
            width: 450px;
        }
        h1 {
            margin-bottom: 5px;
            font-size: 26px;
            text-align: center;
        }
        h2 {
            margin-bottom: 30px;
            font-size: 20px;
            text-align: center;
        }
        .block {
            margin: 0 auto 12px;
            display: flex;
            align-items: center;
        }
        label {
            display: block;
            line-height: 40px;
            background-color: #47356E;
            color: #eee;
            text-align: center;
        }
        textarea {
            padding: 10px;
            width: 100%;
            font-size: 14px;
            border-radius: 0;
            border: 2px solid #04181F;
            outline: none;
            resize: none;
            text-align: center;
            margin: 0;
        }
        button {
            display: inline-block;
            padding: 15px;
            background-color: #F68802;
            color: #eee;
            outline: none; 
            border: none;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            text-decoration: none;
            text-align: center;
            transition: all .2s;
            margin-top: 5px;
        }
        button:hover {
            opacity: 0.9;
        }
        .output {
            display: block;
            width: 100%;
            margin-top: 12px;
            padding: 20px 0;
            background-color: #2F4C58;
            font-size: 16px;
            text-align:center;
            color: #f3f3f3;
            line-height: 1.5;
        }
        .hide {
            display: none;
        }
    </style>
</head>
<body>
    <main class="container">
        <h1>Count Consonants and Vowels<br>Using JavaScript</h1>
        <h2>Jake R. Pomperada, MAED-IT, MIT</h2>
        <form action="" id="frmCount">
            <label for="grade1">Enter a sentence:</label>
            <textarea name="" id="txtContent" rows="3" required></textarea>
            <button type="submit">Count</button>
            <div class="output hide"></div>
        </form>
    </main>

    <script>
        document.querySelector('#frmCount').onsubmit  = (e) => {
            e.preventDefault()

            let content = document.querySelector('#txtContent').value,
                output = document.querySelector('.output'),
                countConsonants = () => {
                    return content.match(/[^aeiou\s]/gi).length
                },
                countVowels = () => {
                    return content.match(/[aeiou]/gi).length
                }

            output.classList.remove('hide')
            output.innerHTML = 'Number of Vowels: '+countVowels()+'<br>'+
                               'Number of Consonants: '+countConsonants()+'<br>'
        }
    </script>
</body>
</html>

Leave a Reply

Your email address will not be published.