how can I solve this. It is supposed to make all vowels in str capitalized and to change each letter in the alphabet to the next letter in the alphabet(i.e. a -> b, or z->a). It keeps returning "str.join is not a function". Any Help? By the way, it's JavaScript.
function LetterChanges(str) {
str = str.split("");//split() string into array
for(var i=0;i<str.length;str++){//for loop that checks each letter
if(str[i]===/[^a-y]/){
str=str[i].fromCharCode(str[i].charCodeAt(0) + 1);
}else if(str[i]==='z'){
str[i] = 'a';
}
if(str[i] === 'a'||'e'||'i'||'o'||'u'){
str[i] = str[i].toUpperCase();
}
}
//modifies letter by adding up in alphabet
//capitalizes each vowel
//join() string
return str.join();
}
// keep this function call here
// to see how to enter arguments in JavaScript scroll down
LetterChanges(readline());
Ok, you need to read a bit on JavaScript.
This is doesn't do what you think str[i]===/[^a-y]/
. You should use str[i].match(/[a-y]/i)
.
This doesn't do what you think: str[i] === 'a'||'e'||'i'||'o'||'u'
. It'll always return true. You'll want this str[i].match(/[aeiou]/i)
.