JavaScript - Simple Counting Words
Submitted by razormist on Friday, January 18, 2019 - 22:09.
Learn on how to create a Simple Counting Words using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It can renders web pages in an interactive and dynamic fashion. It is widely used in designing a stunning website. So Let's do the coding...
There you have it we successfully created a Simple Counting Words 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!
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.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-6">
- <div class="form-group">
- </div>
- <center>
- </center>
- <br />
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will count the words in the sentence when 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 folder.- function count() {
- var words = document.getElementById("words").value;
- var count = parseInt(words);
- count_word=words.split(" ");
- document.getElementById("result").innerHTML =
- "<center>The number of words in the sentence has<br /><label class='text-primary' style='font-size:35px;'>" +
- count_word.length + "</label>words</center>";
- }
- function reset(){
- document.getElementById("result").innerHTML = "";
- document.getElementById("words").value="";
- }
Add new comment
- 64 views