JavaScript - Simple Remove Vowels

In this tutorial we will create a Simple Remove Vowels using JavaScript. This code will remove all the vowels in a word when the user click the remove button. The code use replace method to highlight the vowels of the word in order to remove them in place. This program is a user-friendly feel free to use it in your system. We will use JavaScript to allow you to implement complex things on web pages. It enables you to create dynamically updating content and add some interactive visual for the user transactions.

Getting Started:

This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

The Main Interface

This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.         <head>
  4.                 <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5.                 <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
  6.         </head>
  7.         <nav class="navbar navbar-default">
  8.                 <div class="container-fluid">
  9.                         <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  10.                 </div>
  11.         </nav>
  12.         <div class="col-md-3"></div>
  13.         <div class="col-md-6 well">
  14.                 <h3 class="text-primary">JavaScript - Simple Remove Vowels</h3>
  15.                 <hr style="border-top:1px dotted #ccc;"/>
  16.                 <div class="col-md-2"></div>
  17.                 <div class="col-md-8">
  18.                         <a class="btn btn-success" href="index.html"><span class="glyphicon glyphicon-refresh"></span> Reset</a>
  19.                         <button class="btn btn-danger" onclick="displayStr();"><span class="glyphicon glyphicon-remove"></span> Remove Vowels</button>
  20.                         <br /><br />
  21.                         <div id="result" align="justify" style="padding:10px; border:1px solid #000;">It was, as far as I can ascertain, in September of the year 1811 that a post-chaise drew up before the door of Aswarby Hall, in the heart of Lincolnshire. The little boy who was the only passenger in the chaise, and who jumped out as soon as it had stopped, looked about him with the keenest curiosity during the short interval that elapsed between the ringing of the bell and the opening of the hall door. He saw a tall, square, red-brick house, built in the reign of Anne; a stone-pillared porch had been added in the purer classical style of 1790; the windows of the house were many, tall and narrow, with small panes and thick white woodwork.</div>
  22.                 </div>
  23.         </div>
  24. <script src="js/script.js"></script>   
  25. </body>
  26. </html>

Creating the Script

This code contains the script of the application. This code will remove all the vowels in a word when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
  1. function displayStr(){
  2.         var data = document.getElementById('result');
  3.         data.innerHTML = removeVowels(data.innerHTML);
  4. }
  5.  
  6. function removeVowels(str){
  7.         return str.replace(/[aeiou]/gi, '');
  8. }
There you have it we successfully created a Simple Remove Vowels using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment