Whale Talk

This question is in regards to step 9 for the project at the following URL: https://www.codecademy.com/paths/back-end-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-loops/projects/whale-talk

Step 9 states:

Whales double their e ‘s and the u ‘s in their language.

Write an if statement that checks if each letter in the input string is equal to 'e' . If so, .push() input[i] to the resultArray .

Note, this statement belongs after the inner for loop block inside the outer for loop. This is because you only want to perform this check once for every letter in the input .

My question is - if the letter in the input string is equal to 'e' , wouldn’t we want to '.push()' 'ee' and not 'input[i]'? Also, in regards to the the note in step 9, why would the statement need to go after the inner 'for' loop block? I checked the input for 'e' letters immediately after the outer for loop and it worked just fine-every letter in the 'input' will still be checked only once (maybe, I am misunderstanding what they meant by this.). Here is my code below.

let input = 'a whale of a deal!';

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

const resultArray = [];

for (i=0; i<input.length; i++){
  if (input[i]==='e') {
   } else if (input[i]==='u') {
    for (v=0; v<vowels.length; v++){
      if (input[i]===vowels[v] && input[i]!=='e' && input[i] !=='u') {


You can, but it requires this code:

If you just push "e", then the next instruction or two should tell you to push any vowel after pushing "e", thus either pushing "ee", "uu" or just one vowel. But your way does work.

1 Like

I believe you could benefit from using the OR operator ||. That could allow you to check if any one of multiple conditions are true in one if statement.

My question is - if the letter in the input string is equal to 'e' , wouldn’t we want to '.push()' 'ee' and not 'input[i] '?

I would recommend sticking with input[i], which would be required to check for u and e with only one if statement. Remember, you could always just .push() your input[i] twice like so: .push(input[i], input[i]).

I hope I’ve given enough of a hint without just handing over the answer, but I’d be happy to link my entire code. (You can also find my code linked in a reply I left on another thread, if you don’t want to wait. Just check my profile, it was the last thing I did)