Question

In: Computer Science

Hey, how do I create a function which receives one argument (string). The function would count...

Hey, how do I create a function which receives one argument (string). The function would count and return the number of alphanumeric characters found in that string. function('abc 5} =+;d 9') // returns 6 in JavaScript?

Solutions

Expert Solution

CODE:

<!DOCTYPE html>
<html>
<head>
   <title>Alnum Count</title>
</head>
<body>
<p id="input"></p> <! -- to print input-->
<p id="count"></p> <! -- to print count -->
<script>//script tag to write the function.
var string=prompt("Enter string : ");//taking input from the user
document.getElementById("input").innerHTML="The user input is : "+string;//printing the input.
var count=alnum(string);//function returnds the count of alpha numeric characters.
//Printing the count returned from the function.
document.getElementById("count").innerHTML = "The count of alpha numberic characters is : "+count;
//function that returns the count of alpha numeric.
function alnum(str) {
   var i;//loop variable.
   var count=0;//count variable.
   for(i=0;i<str.length;i++)//loop iterates through the string.
   {
       //condition to check number or lowercase alphabet or uppercase alphabet.
       if((str[i]>='0' && str[i]<='9') ||(str[i]>='a' && str[i]<='z') ||(str[i]>='A' && str[i]<='Z'))
       {
           ++count;//increment count if condition satisfied
       }
   }
   return count;//returning the count.

}
</script>
</body>
</html>

CODE ATTACHMENTS:

prompt:

OUTPUT:

Please do comment for any queries.
PLease like it.
Thank You.


Related Solutions

In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Suppose a function receives a pointer as an argument. Explain how this function is declared within...
Suppose a function receives a pointer as an argument. Explain how this function is declared within its calling function. In particular, explain how the data type of the pointer argument is represented. C++
Creates a function called pick. The function receives a "string" representing one year (the variable with...
Creates a function called pick. The function receives a "string" representing one year (the variable with this "string" will be called uve) and a list containing "strings" representing bank accounts (call this bera list). <br> • Each account is represented by 8 characters. The format of each account number is "**-**-**", where asterisks are replaced by numeric characters. o For example, "59-04-23". • The two central characters of the "string" for each account represent the year the account was created....
Complete the function, MycountWords in C++, which will count the number of words in a string....
Complete the function, MycountWords in C++, which will count the number of words in a string. We will have different word separators(such as newline(\n), spaces, special symbols(? | \ , . : ;) ) That will separate the words in the giving istringstream. Remember if a words is separated by a hyphen and followed by a new line, they're still one word. The function has an option to be sensitive to case and also avoid duplicates. for duplicates, this is...
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special...
PYTHON Define a function named variousChanges(...) which receives one string (origst) (with letters, digits or special characters), possibly empty, and returns a new string containing the following. a) in those positions where the original string has an even digit, the corresponding character in the new (returned) string should have the string digit '0' b) in those positions where the original string has a vowel letter (upper or lower case), the new (returned) string should have the letter 'V'. Note that...
Function 6: Sorting string function name (str) a. This function receives an string. Your task is...
Function 6: Sorting string function name (str) a. This function receives an string. Your task is loop through the each character of the string and separate all digists/letters/special characters. Display all digits at the beginning, followed by letters then the special chars and display result in console. For example if following string is passed to this function “ha1m2i3:n)” Result should be: 123hamin:)
Hi! I wrote two function to get count cluster of char in a string , charFreq(),...
Hi! I wrote two function to get count cluster of char in a string , charFreq(), and an other one which iterate through a vector line by line looking for last element on each line, last(). The problem is, after appending all chars in a string and try to count clusters of values in that string, I get seg fault. I feel like my logic behind is ok, but I am not sure what I did wrong. Can someone help...
Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of...
Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the a Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume object. The remaining lines consist of a single character followed by a space followed by...
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The...
In PYTHON: Write a function that receives an encrypted string and decrypts it as follows. The decryption does not change the lowercase letters ‘e’, ‘w’, and ‘l’ (lowercase L). For any other character, we change it to a number using ord(). We then take the number to a power of 19, and then find the remainder after diving by 201. Finally, we take the character corresponding to the number we obtained (using chr()). For example, assume that we receive the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT