I'm a newbie on Javascript and I'm trying to do some exercises. I have found other ways on here that are more efficient at solving this, but anyway, here's how I tried doing it:
var char = prompt("Give me a letter");
char = char.toLowerCase();
function isVowel(char){
var vowels = new Array('a','e','i','o','u');
for(i = 0; i < vowels.length; i++){
if(vowels[i] == char){
return "This letter is a vowel.";
}else{
return "This letter is not a vowel.";
}
}
}
alert(isVowel(char));
Now, I understand this isn't the best way to do this, but I'd like to understand what's wrong with my for loop, since "a" is the only letter it recognizes as being a vowel. Can someone point me out the reason why it isn't running trough the whole array?
Thanks in advance