Help with Whale Project Loops Section,

Hello, I am on Step 10, of the Whale Project and all I produced was an empty pair of brackets! i.e. empty Array. The statement says that if there’s and E or a U in the Array, input[inputIndex] and then it’s supposed to return a double E , or a double U… Please can you help?

const input = "I've no idea, have you";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for(let inputIndex = 0; inputIndex < input.length; inputIndex++){
  //console.log("inputIndex = " + inputIndex);
  //S5

for (let v2 = 0; v2 < vowles.length; v2 ++){
  //console.log(v) Stp 7 Ends
  if(input[inputIndex].toLowerCase === vowles[v2]){
    resultArray.push(input[inputIndex]);
  if(input[inputIndex] === `e`){
  resultArray.push(`ee`);
  }
  else if (input[inputIndex] === "u"){
    resultArray.push(`uu`); //End of Step 10
  }
  else{
    resultArray.push(input[inputIndex]);
  }
  }
}
} 

console.log(resultArray)



the result array is empty, which seem to suggest this condition:

if(input[inputIndex].toLowerCase === vowles[v2])

never evaluates to true, so what you could to debug this is to log the values used in the comparison:

console.log(input[inputIndex].toLowerCase, vowles[v2])

Hi’
Thanks for the line of code earlier. I am now engage in the debugging process…

I believe it is the If statement that’s the problem… because its only supposed to return, the input array that is equal to the vowles array, but that first if statement is returning a continuous string of all the vowles. How do I get the result, that I want?

const input = "I've no idea, have you";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for(let inputIndex = 0; inputIndex < input.length; inputIndex++) {//its th Array inth Methd that Points
  //console.log("inputIndex = " + inputIndex);
  //S5
for (let v2 = 0; v2 < vowles.length; v2 ++){
  ////its th Array inth Methd that Points.
//console.log("v is " +v2)

for (let v2 = 0; v2 < vowles.length; v2 ++){
  //console.log(v) Stp 7 Ends

  if(input[inputIndex].toLowerCase === vowles[v2]){
    resultArray.push(input[inputIndex]);
  
  }
  }
 console.log(input[inputIndex].toLowerCase, vowles[v2])
}
}

when you apply console.log to the result array that also shows an error message… But that would be the goal. If i could actually get the If statement to return a result to the result array?

I agree here, but after this, you lost me.

that make sense? we need to compare each character of input with each vowel to see if its possible a vowel

you are missing the whole point? Look at the output. You attempting to compare a function and a string, that is never going to be true.

Hi’
Thanks for getting back to me. I realise there was an unnecessary .push to the result array, underneath the first If statements, So I removed that, and applied the second If statement. Still receiving error message.

Have applied the console.log at different lines to no effect!

const input = "I've no idea, have you";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for(let inputIndex = 0; inputIndex < input.length; inputIndex++) {//its th Array inth Methd that Points
  //console.log("inputIndex = " + inputIndex);
  //S5
for (let v2 = 0; v2 < vowles.length; v2 ++){
  ////its th Array inth Methd that Points.
//console.log("v is " +v2)

for (let v2 = 0; v2 < vowles.length; v2 ++){
  //console.log(v) Stp 7 Ends

  if(input[inputIndex].toLowerCase === vowles[v2]){

  if(input[inputIndex] === `e`){
  resultArray.push(`ee`);
  
  }
  }
console.log(resultArray); 
  }
}; 

You should take a step back and first think about how to solve this problem. I would recommend the following approach:

check if is vowel, if vowel push to results array
do another check if vowel is e or u, if so, add another one of these vowels to result array

so then you most certainly need the .push() you just removed

you still have not fixed this line:

if(input[inputIndex].toLowerCase === vowles[v2])

you are still not calling toLowerCase correctly, resulting in an incorrect comparison.

you should also indent your code properly, the error you currently have seems related to missing closing (curly) bracket. With the right indention, finding such a mistake is a lot easier

why do you have this loop twice:

for (let v2 = 0; v2 < vowles.length; v2 ++){
  ////its th Array inth Methd that Points.
//console.log("v is " +v2)

for (let v2 = 0; v2 < vowles.length; v2 ++){

what are you doing?

I didn’t want to write the .toLowerCase on there, its not a requirement of the question. One of the other moderators made me do!

you don’t have to? there are alternative solutions, like adding uppercase vowels to your vowels array (you misspelled vowels)

handling uppercase should be a requirement in my opinion

I’m not understanding the check…

check if is vowel, if vowel push to results array

if(input[inputIndex] === vowles[v2]){

this is the if statement, and it definitely has vowles in it…

However this statement is regarding step 8…

Inside the second for loop, write a code block that compares the input letter to every letter in the vowels array.

I have coped Step 8 in the statement above and as you can see… it is a very small sentence to complete and there is no… mention here of using .push to push the result to the result array?

Tom?

You would need to provide me with the exercise url, I would need to see the instructions

I think I’ve figured it out. It’s because the first if statement has to be inside the execution bracket, of the second loop… “I think.”

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.