Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

must be written in javascript. as well as use the parametrized function StringSt

ID: 3731585 • Letter: M

Question

must be written in javascript. as well as use the parametrized function StringStats(sentence).

Question #4 Write a Javascript function StringStats(sentence) in that takes in a user specified sentence and prints the words along with number of vowels present in the word. For a word without a vowel you should print "contains 0 vowels". The sentence to be used is "The word rhythms doesn't contain any vowels". Hint: Use the match method with /i for case insensitivity The page should display the following result String Statistics: The contains 1 vowel word contains 1 vowel rhythms contains 0 vowels doesn't contains 2 vowels contain contains 3 vowels any contains 1 vowel vowels contains 2 vowels

Explanation / Answer

Following is the java script code:

<html>

<head>

<script type="text/javascript">

var s = "The word rhythms doesn't contain any vowels";  

var ss = s.split(" ");  

for (var i in ss) {  

document.write(ss[i] + " Contains " + vowel_count(ss[i]) + " Vowels.");

document.write("<br/>");

}  

function vowel_count(str1)

{

var vowel_list = 'aeiouAEIOU';

var vcount = 0;

  

for(var x = 0; x < str1.length ; x++)

{

if (vowel_list.indexOf(str1[x]) !== -1)

{

vcount += 1;

}

  

}

return vcount;

}

</script>

</head>

<body>

</body>

</html>