Question

In: Computer Science

javaScript html receives an entry of a character string in a text box, when a button...

javaScript

html receives an entry of a character string in a text box, when a button is clicked, the count of vowels in the string stored in the textbox is displayed. The html file contains one function: vowelcount().

vowelcount(): returns the number of uppercase and lowercase English language vowel letter that occurs in the string entry in the textbox.

//html:

<!--

   YOUR ID
   YOUR NAME

-->
<html>
<head>
<script>
function vowelcount()
{
       /* YOUR CODE HERE */
}

</script>
</head>
<body>
<input type="text" name="numbers" id="numbers">
<input type="button" name="button" value="click" onclick="vowelcount();">
<p id="result"> </p>
</body>
</html>

Solutions

Expert Solution

Answer:

Note: Updated code highlighted in bold.

Code:

<!--
YOUR ID
YOUR NAME
-->
<html>
<head>
<script>
function vowelcount()
{  
   //getting string from textbox
   var string = document.getElementById("numbers").value;
var listOfVowels = 'aAeEiIoOuU';
var vowelsCount = 0;
for(var i = 0; i < string.length ; i++)
   {
       //if character is matched with listOfVowels
if (listOfVowels.indexOf(string[i]) !== -1)
       {
vowelsCount += 1; //increment the count
}
}
   //Setting result to result element
   document.getElementById('result').innerHTML = "Number of Vowels: "+vowelsCount;
}

</script>
</head>
<body>
<input type="text" name="numbers" id="numbers">
<input type="button" name="button" value="click" onclick="vowelcount();">
<p id="result"></p>
</body>
</html>

Screenshot:


Related Solutions

Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript">...
Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript"> funtion oldMacVerse(animal, sound) //Assumes: animal is the name of an animal, sound is the sound it makes //Results: displays a version of the song "Old MacDonals Had a Farm" in outputDiv { document.getElementById('outputDiv').innerHTML =    '<p>Old MacDonald had a farm, E-I-E-I-O.<br>' +    'And on that farm he had a ' + animal + ', E-I-E-I-O.<br>' +    'With a ' + sound +...
Using Javascript Create a page places an order for a Calzone: Using Text box to get...
Using Javascript Create a page places an order for a Calzone: Using Text box to get customers Name Radio Buttons for sizes: small, medium, large list for type of crust: crispy, soft, hard check boxes for toppings, with at least 3 to be selected Submit button that displays the order information.
2. The HTML document on the following page consists of JavaScript code executed when the document...
2. The HTML document on the following page consists of JavaScript code executed when the document is loaded. It prompts the user for his/her name (first and last names) then outputs the greeting “Hello Mr. _____!” or “Hello Ms. _____!” (where _____ is the user’s last name) depending on whether the first name is recognized as a male name. (In the code, only three male names are checked; a realistic program would check many more names.) We allow for the...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ?...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ? Car Rental Enter Number of Rental Days: Select Car Type: onclick= "priceofcar = 50;"/> Compact onclick= "priceofcar = 60;"/> Economy onclick= "priceofcar = 70;"/> Intermediate Select Loss Damage Waiver onclick= "damagewaiver='yes'"/> Yes onclick= "damagewaiver='no'"/> No damagewaiver = boxDays.value * 25;} else if (damagewaiver == No) { damagewaiver = 0; }/> Select Roadside Issues Coverage: onclick= "issuescoverage='yes'"/> Yes onclick= "issuescoverage='no'"/> No issuescoverage = boxDays.value *...
JavaScript Form Validation Name: a text box where the content must start with 1 upper case...
JavaScript Form Validation Name: a text box where the content must start with 1 upper case characters and no special character (i.e. !, @, #, $, %, &, *). Number is not allowed. The text box must not be empty. Module code: a text box where the content must start with 3 lower case alphabets and follows by 4 digits where the first digit cannot be zero. This textbox can be empty. All validation error messages must be italic and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT