What is wrong with this code

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hello Everyone,

I’ve gone through the Whale Tale element for Web Development.

The Code I’ve written will print four letters of the words being inputted. However, I cannot get the whale version to print 'UUEEIEEAUUEE'.

const input = 'turpentine and turtles';

const vowels = ['a', 'e', 'i', 'o', 'u'];

let resultArray = [];

for (let inputIndex = 0; inputIndex < input.length; inputIndex ++){

  for(let vowel = 0; vowel < 
      vowels.length; vowel++ ){
    if(input[inputIndex] === 
      if(input[inputIndex] === 'e'){resultArray.push('ee');}
    else if(input[inputIndex] === 'u'){resultArray.push('uu');}

If you keep your formatting consistent it’ll be easier to see what’s going on, you’ve got newlines in odd places and pushed together things into the same line that really don’t need to be on the same line.

inputIndex could be named i so that it doesn’t dominate your vision being mentioned everywhere

you can also make it easier for yourself if you do the filtering of vowels/nonvowels and the mapping of e/u separately from each other eg

here's my input

keep only the vowels

change e to ee

change u to uu

^ that can be a sequence of separate actions, doesn’t need to be all nested within one another in the same place