xxxxxxxxxx
// check the word is vowel or not
let words = "aeiou";
let newWords = "";
function isVowelOrNot(words) {
for (let word of words) {
if (
word === "a" ||
word === "e" ||
word === "i" ||
word === "o" ||
word === "u"
) {
newWords = newWords + word;
}
}
if (newWords === words) {
return true;
} else {
return false;
}
}
let result = isVowelOrNot(words);
console.log(result);
xxxxxxxxxx
const encode = (string) => {
let newStringArray =string.split("").filter(
(ch) => ch === "a" || ch === "e" || ch === "i" || ch === "o" || ch === "u"
);
return newStringArray;
};
encode('football').forEach(vowel=>{
console.log(vowel);
})
//o
//o
//a
xxxxxxxxxx
<!doctype html>
<html>
<head>
<script>
var ch;
function checkVowel()
{
ch = document.getElementById("char").value;
if(ch)
{
temp = document.getElementById("resPara");
temp.style.display = "block";
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
{
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
document.getElementById("res").innerHTML = "a Vowel";
else if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
document.getElementById("res").innerHTML = "a Vowel";
else
document.getElementById("res").innerHTML = "a Consonant";
}
else
document.getElementById("res").innerHTML = "neither Vowel nor Consonant";
}
}
</script>
</head>
<body>
<p>Enter the Character: <input id="char"><button onclick="checkVowel()">Check</button></p>
<p id="resPara" style="display:none;">It is <span id="res"></span></p>
</body>
</html>