JS II : Loop <Whale Talk Project>

Hi! I just finished the whale talk project, I just have to clarify on this if somebody can help me out I’d really appreciate it.

This is what I came up with (had to watch the walkthrough video):

const input = 'i love you'
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];

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

The question I have is that: are all the consonants from the variable input gone because (input[i] !== vowels[j]) is undefined, and is simply falsy? (There is no ‘else’ conditional for the first ‘if’.)
Just wanted to clarify! Thank you.

Hello,

Indeed, no consonant will ever be considered because they do not match the condition of your first if – and you’ve not given them any alternative.

You could try specifying an else condition, just to check the result.

1 Like

Thank you so much! :smiley: