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

In javascript, Add a method named insertStep that receives a String and an int. It adds...
In javascript, Add a method named insertStep that receives a String and an int. It adds the String to the collection of instructions, before the step whose index is the int. You may assume that the user won’t try to insert something before a step that doesn’t exist.
Project 2c (Javascript/HTML/CSS)– Mouse Chase: Create a page with a nice, shiny, pretty button on it....
Project 2c (Javascript/HTML/CSS)– Mouse Chase: Create a page with a nice, shiny, pretty button on it. The button should say ‘Click to receive $10!’ However, any time the user’s mouse cursor gets over the button, the button should move to a random location on the page, making the button essentially impossible to click! However, if they do somehow manage to click the button, redirect the user to an image of a 10 trillion Zimbabwe Dollar. Finally, the background color of...
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 +...
<!DOCTYPE html> <html lang="en"> <head>    <title>Form Display Example</title>    <script type="text/javascript">    function display() {...
<!DOCTYPE html> <html lang="en"> <head>    <title>Form Display Example</title>    <script type="text/javascript">    function display() {    dispWin = window.open('','NewWin','toolbar=no,status=no,width=300,height=200')       message = "<ul><li>NAME:" + document.form1.name.value;    message += "<li>ADDRESS:" + document.form1.address.value;    message += "<li>PHONE:" + document.form1.phone.value;    message += "</ul>";    dispWin.document.write(message); } </script> </head> <body>    <h1>Form Display Example</h1>    <p>Enter the following information. When you press the Display button, the data you entered will be displayed in a pop-up.</p>    <form name="form1" method="get" action="">   ...
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