Whale Talk Javascript Looping Error

Hi there!

I am having an issue with my Whale Talk project in the Learn Javascript curriculum. I can’t tell from the walkthrough what I am missing here, but the below code produces a weird answer rather than the final, joined string that the project suggests it should.

Here’s my code:

var input = "A whale of a deal";
const vowels = ['a', 'e', 'i', 'o', 'u'];
var resultArray = [];

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

//if(input[indexInput] === 'u') {
    //resultArray.push('uu')
 // }

And here’s the result it creates:
A
A
A
A
A
A
A
A
A
A
A
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEE
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEO
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOA
AEEOAEE
AEEOAEE
AEEOAEE
AEEOAEE
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
AEEOAEEA
[/codebyte]

I must be missing something super obvious, but I just can’t seem to figure it out! Any help would be much appreciated!

If you move your console.log(resultArray.join(’’).toUpperCase()) out of the loop and put it to the end of the code, this is the output: ‘AEEOAEEA’.
That’s what you want, right? Right now you’re printing and joining the array each time the loop runs.

1 Like

That’s definitely it! Thanks!

1 Like