Accept a character from the user and check whether the character is a vowel or consonant
Table of Content -
- We are taking input from the user.
- Process the input
- Match this input with an array of vowel
- If matched then it's a vowel otherwise consonant
Let's start code form here ---
source code -
Check Enter Value is vowels or consonant!
Enter any character
<h1>Check Enter Value is vowels or consonant!</h1>
<p>Enter any character <input type="text" id="vowelsCheck" value="a" onkeyup="myFunction()" oninput="this.value = this.value.replace(/[^a-zA-Z]/g, '').replace(/(\..*)\./g, '$1');"></p>
<p id="output"></p>
<script>
const vowels = ['a','e','i','o','u','A','E','I','O','U'];
function checkvowels(Vchar) {
return Vchar == document.getElementById("vowelsCheck").value;
}
function myFunction() {
if(vowels.find(checkvowels)!=undefined){
document.getElementById("output").innerHTML = vowels.find(checkvowels)+" is vowels!";
}else{
document.getElementById("output").innerHTML = document.getElementById("vowelsCheck").value +" is a consonants";
}
}
myFunction();
</script>
0 Comments