Whale Talk

Hi everyone!
My code is not working, why?

const input = "how are you";
const vowels = ["a", "e", "u", "o", "i"];
let resultArray = [];
for (let inputIndex = 0; inputIndex < input.lenght; inputIndex++) {
  for (let vowel = 0; vowel < vowels.length; vowel++) {
    if (input[inputIndex] === vowels[vowel]) {
      if (input[inputIndex] === 'e') {
        resultArray.push('ee');
      }
      else if (input[inputIndex] === 'u'){
        resultArray.push('uu');
      }  
      else {
          resultArray.push(input[inputIndex])
      }
    }
  }
}
console.log(resultArray.join('').toUpperCase());

You have a typo that is causing issues in your outer for loop. Due to this, it never meets the conditions to start the loop.

Click here if you don't spot it

You wrote input.lenght instead of input.length in your outer for loop.

1 Like