Whale-talk

Hello,

I am working on the Whale Talk exercise for the Loops section.

This is my code so far after doing the step to double the 'e’s:

const input = "I am a whale";
const vowels = ["a", "e", "i", "o", "u"];
let resultArray = [];

for (let i = 0; i < input.length; i++) {
  if (input[i] === "e") {
    resultArray.push(input[i]);
  }
  for (let j = 0; j < vowels.length; j++) {
    if (input[i] === vowels[j]) {
      resultArray = vowels[j];
    }
  }
}

When I run it, it returns:
Output:
/home/ccuser/workspace/learn-javascript-loops-P1/main.js:7
resultArray.push(input[i])
^

TypeError: resultArray.push is not a function

I can’t figure out what’s wrong with this code. The resultArray.push portion even looks the same as the walkthrough video to me but clearly I’m missing something. Any help is appreciated, thanks.

const input = "I am a whale";
const vowels = ["a", "e", "i", "o", "u"];
let resultArray = [];

for (let i = 0; i < input.length; i++) {
  if (input[i] === "e") {
    resultArray.push(input[i]);
  }
  for (let j = 0; j < vowels.length; j++) {
    if (input[i] === vowels[j]) {
      // right here you reassigned your array into a string
      resultArray = vowels[j];
      // ^this should be resultArray.push(input[i])
    }
  }
}
1 Like

Ahhh I see, I didn’t realize it worked like that! Thank you!!