3. (E) Write a program in JavaScript to accept a sentence from the user and display the number of words in it. (Do not use split () function).
3. (E) Write a program in JavaScript to accept a sentence from the user and display the
number of words in it. (Do not use split () function).
<html>
| ||
<title>Without using split function</title> | ||
<script> | ||
function myfun(){ | ||
var str=document.getElementById("input").value; | ||
var count=0; | ||
for(i=0;i<str.length;i++) | ||
{ | ||
if(str.charAt(i,1)==" " && str.charAt(i+1,1)!=" ") | ||
count++; | ||
} | ||
alert("Number of words are="+(count+1)); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<form> | ||
ENTER THE SENTENCE : <input type="text" id="input"><br><br> | ||
<input type="submit" onclick="myfun()"> | ||
</form> | ||
</body> | ||
</html> |
3. (E) Write a program in JavaScript to accept a sentence from the user and display the number of words in it. (Do not use split () function).
Reviewed by admin
on
December 24, 2019
Rating:
No comments: