Whale talk project

Hi guys,

I am trying to finish this javasript project - I am guessing that trying to use 2nd if statement using OR its responsible for bugging.

Can someone help me with how to finish it please ?

const input = 'turpentine and turtles';
const arrayVowels = ['a','e','i','o','u'];
const resultArray = [];
for (let i = 0; i < input.length; i++) {
  //console.log('Number of characters is '+i);
  for (let j = 0; j < arrayVowels.length; j++)
  //console.log('j  is '+j);
     if (input[i] === arrayVowels[j]) {
       if (input[i] === 'e' || input[i] === 'u') {
     resultArray.push('ee', 'uu');
      }  else {

With your second condition you are pushing “ee” AND “uu” to the array for each occurrance of e or u. I guess that not what you want?

1 Like

const input = ‘turpentine and turtles’;

const vowels = [‘a’, ‘e’, ‘i’,‘o’,‘u’]

const resultArray =

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

for (let vowelsIndex = 0; vowelsIndex < vowels.length; vowelsIndex ++)
console.log(vowelsIndex is ${vowelsIndex})

Can someone explain how the the result was printed out in this case? I still feel confused how it works

Thanks a lot

Which result? In the code you’ve written, you’re just printing out the index of each vowel (a,e,i,o,u) in the vowels array.

It looks as though you are telling the console to log 'ee and ‘uu’, if e or u is found, which is why the string is starting EEUUEEUU. You need to add one or the other. You need to think, “what do i want the computer to do for me?”

  1. We want it to check for any vowels that match the input
  2. we want it to push any matching vowels to resultArray
  3. if ‘e’ or ‘u’ is found. then we want to double it.

in order to ensure consistency in the text, and the double ups, this should be actioned in 1 loop

  1. create a for loop to loop through input, using two seperate if statements, push an ‘e’ to resultArray if found, or ‘u’ to resultArray if found.
  2. within the same for loop, we now want to scan for any matching vowels between input and arrayVowels, if found, then push the match through to resultArray.

Doing this will double up any e’s or u’s.

I hope this helps you :slight_smile: Good luck on your journey, and remember it’s perfectly normal to hit road blocks!