Question

I keep getting "Type Error: str.join is not a function. This code is supposed to take a string input and make each letter in the input the next letter(i.e. a->b,z->a) and capitalize every vowel. Does anyone know why it's still wrong?

str = str.split("");//split() string into array
  for(var i=0;i<str.length;str++){//for loop that checks each letter
    if(str[i].match(/[a-y]/i)){
      str[i]=String.fromCharCode(str[i].charCodeAt(0)+1);
        }else if(str[i].match('z')){
          str[i] = 'a';
        }
    if(str[i].match(/[aeiou]/i)){
       str[i] = str[i].toUpperCase();
       }

  }
   str2= str.join('');
  //modifies letter by adding up in alphabet
  //capitalizes each vowel
  //join() string


  return str2; 
}

// keep this function call here 
// to see how to enter arguments in JavaScript scroll down
Was it helpful?

Solution

You're accidentally incrementing str when you should be incrementing i:

for(var i=0;i<str.length;str++){//for loop that checks each letter
                          ^---// replace str with i

I don't know if the rest of your code works, but this would explain that particular error.

OTHER TIPS

In the beginning of the loop you have for(var i=0;i<str.length;str++){, change that to for(var i=0;i<str.length;i++){ (you're looping based on an iteration that doesn't exist)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top