Hey everyone,
I literally just started to learn Javascript today and started with a function that takes in a string and tells you the number of vowels (a,e,I,o,u) in it. It works, but when I use document.write(vowel("hello")) in my body, instead of just giving an output of "this string has 2 vowels in it!", it outputs:
this string has 2 vowels in it!
undefined
Whats going on, here is my code for the function:
function vowel(string)
{
var count = 0;
string = string.toLowerCase();
for (i=0;i<string.length;i++)
{
if (string.charAt(i) == "a" || string.charAt(i) == "e" || string.charAt(i) == "i" || string.charAt(i) == "o" || string.charAt(i) == "u")
{
count++;
}
}
document.write("this string has " + count + " vowels in it! <br />");
}