Here is a sample program that I wrote will count the number of words in a given sentence by our user using JavaScript as our programming language. The code is very simple and easy to understand I intended my work for beginners that are new in JavaScript programming.
If you like my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
People here in the Philippines who wish to contract me through my mobile number can reach me in this number 09173084360.
Thank you very much and God Bless.
Program Listing
<html>
<title>Word Counter in Javascript</title>
<style>
body {
font-size:20px;
font-family:arial;
color:blue;
}
input {
display: table-cell;
}
div.justified {
display: flex;
justify-content: center;
}
</style>
<script language="JavaScript">
function count_words()
{
var words_count =document.getElementById("sentence").value.split(' ').length;;
document.getElementById("word").value= words_count;
}
function clear_me() {
document.getElementById("sentence").value="";
document.getElementById("word").value="";
document.getElementById("sentence").focus();
}
</script>
<body style='background-color:lightgreen'>
<div style='width:1100px;margin:auto'>
<br> <h1 align="center">Words Counter in Javascript</h2>
<div class="justified">
<textarea name="sentence" id="sentence" cols="80" rows="5" autofocus></textarea>
<br /> </div>
<br><center> <button onclick="count_words();"
title="Click here to find the number of words in a sentence.">
Count Number of Words</button>
<button onclick="clear_me();" title="Click here to clear text fields.">
Clear</button> </center>
<br> <br>
<div class="justified"><label> The number of words in a sentence is <input id="word" size="5" readonly> . </label> <br> </div>
</body>
</html>
No comments:
Post a Comment