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

Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The...
Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam Use of any built in string function...
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...
Using HTML and JAVASCRIPT Create a Content area on the main entry page will include inputs...
Using HTML and JAVASCRIPT Create a Content area on the main entry page will include inputs for customer entry for the following: Entry field (with labeling) for the Customer's name Entry field (with labeling) for the Customer's email address Entry field (with labeling) for which room the customer is planning on painting Entry field (with labeling) for the width of the room Entry field (with labeling) for the length of the room Entry field (with labeling) using a colour box...
Language HTML and Javascript Here is a string: " Hi, my name is John. I am...
Language HTML and Javascript Here is a string: " Hi, my name is John. I am a student at Rutgers University. I am currently taking a Web Class." 1. Change "Rutgers University" to "RUTGERS UNIVERSITY" 2. Replace "Web Class" to "Web Client and Server side Programming"
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 +...
Create a footer for web page using HTML,CSS,Javascript. The footer should contain 1.Back to top button...
Create a footer for web page using HTML,CSS,Javascript. The footer should contain 1.Back to top button 2.Random logo 3.Copyright content
<!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.
How do I make an HTML JSON button that when clicked will say Hello World!
How do I make an HTML JSON button that when clicked will say Hello World!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT