vowels and consonants in javascript code example
Example 1: find vowel & consonants in a string java script
const str = "The quick brown fox jumps over a lazy dog";
const vowels = str.match(/[aeiou]/gi);
const consonants = str.match(/[^aeiou]/gi);
vowels.concat([''],consonants).forEach(k => { console.log(k); } );
Example 2: vowels consonants javascript
function readLetter() {
return prompt("Type a letter: ");
}
function isVowel(character) {
switch (character) {
case "a":
case "A":
case "e":
case "E":
case "i":
case "I":
case "o":
case "O":
case "u":
case "U":
return true;
default:
return false;
}
}
var letter = readLetter();
if (isVowel(letter)) alert("The letter is a vowel.");
else alert("The letter is consonant.");