Whale talk: outputs too many e's

Hello friends!

I’m having some trouble here. My output is pushing out one too many e’s. Can someone help me spot what I did wrong?

Thanks!

Ro

const input = "turpentine and turtles";
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];

for (let i = 0; i < input.length; i++){
 // console.log('i = ' + i);
  for (let j = 0; j < vowels.length; j++){
    if (input[i] === vowels[j]){
      if (input[i] === 'e'){
        resultArray.push('ee')
      } if (input[i] === 'u'){
        resultArray.push('uu')
      } else[
        resultArray.push(input[i])
      ]
    }
  }
};

console.log(resultArray.join("").toUpperCase());

Oh! I added else in front of my third if statement and it solved my problem!

1 Like

Well done, I spotted another error too:

Should be:

} else { 
  resultArray.push(input[i]) 
}
3 Likes

Ah, thank you Jannes! Very helpful.

1 Like