Codecademy - Whale talk Project

Hello everyone! Here is my results for the codecademy Whale Talk project. Take a look and let me know what you think! what can I do better? What did I miss? Do you have any questions for me? Any feedback would be great. THANKS!

// Step 1
const input = 'a whale of a deal';
// Step  2
const vowels = ['a','e','i','o','u'];
// Step 3
let resultArray = [];
// Step 4
for (let inputIndex = 0; inputIndex < input.length; inputIndex++){
// Step 5 = console.log('i is ' + i);
// Step 6 - nested for loop
  for (let vowelIndex = 0; vowelIndex < vowels.length; vowelIndex++){
  // console.log('J is ' + j); // Step 7 - test code
// Step 8 - compare input letter to every letter in vowel array
    if (input[inputIndex] === vowels[vowelIndex]) {
      // Step 9 & 10 - Double 'e' & Double 'u'
      if (input[inputIndex] === 'e' || vowels[vowelIndex] === 'u') {
        resultArray.push(input[inputIndex],input[inputIndex])
      } else {
        resultArray.push(input[inputIndex])
      }
    }
  } 
}
// Step 11 & 12 - log results and join strings
console.log(resultArray.join('').toUpperCase())
// Test result to check output 
console.log('UUEEIEEAUUEE')
2 Likes

I wrote this code, and it isn’t working.
The result in the console is an empty array . I do not find the mistake:

const input = [‘Chiba shi Inage Ku’];
const vowels = [‘a’, ‘e’, ‘i’, ‘o’, ‘u’];
let resultArray = ;

for (let i = 0; i < input.length; i++) {
for (let j = 0; j < vowels.lngth; 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);

I think if refactor to a function is useful.

function whaleTaranslator(humanText) {
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  let resultArray = [];
  for(let i=0; i < humanText.length; i++) {
    for(let j=0; j < vowels.length; j++) {
      if(humanText[i] === vowels[j]) {
        if (humanText[i] === 'e' || vowels[j] === 'u') {
            resultArray.push(humanText[i],vowels[j])
        } else {
            resultArray.push(humanText[i])
        }
      }
    }
  }
  return resultArray.join('').toUpperCase();
}
console.log(whaleTaranslator('a whale of a deal!'));
const input = [‘Chiba shi Inage Ku’];
//  change to below code will work
const input = ‘Chiba shi Inage Ku’;

hi, the problem is your input variable,
it should be a string, not an array.

in your situation, your loop always compare vowels to a one input array element ‘Chiba shi Inage Ku’
so every compare will not success.

hope it will help you, cheers~

2 Likes

Dear Jhong,

That is so kind of you. Thank you!
I appreciate your solution and understand it now… my question is the forum was written in April, and now it is the end of September. I forgot about that, and Yes! now I can understand that, and many more things.
I eventually, a few weeks ago dropped Codecademy, because of the lack of help when one needs it, some technical glitches and errors that can leave a students stuck, and just a general lack of coherence and quality teaching.
I’ve been taking courses by Colt Steele (Java Script Bootcamp, Java Script Algorithms, Web Development Bootcamp, Git, Linux, etc, all updated in current months of 2021). I am far ahead in the web development program, with a much better mastery of JS. My questions get an answer within hours, and the quality of teaching quizzes and exercises is superb.
Many thanks, and all the best in your journey!

1 Like

Welcome, That’s great.
Codecademy is not good for no any background knowledge people.
Learning with video more good for beginner. :grinning:

Can’t figure out why the first letter is appearing…

let input = "turpentine and turtles";
const vowels = ['a', 'e', 'i', 'o', 'u'];
let resultArray = [];

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

its because e and u are vowels.

The first if-statement puts in the first e or u.
The second [or third] if-statements you have puts in two more.

so there’s three overall.

But why is the first consonant appearing?

you would only like to add the letter if it is a vowel,
so you want to check input[i] is one of the things in the vowels array (one element of vowels at a time), and push input[i] to the array if that is the case.

so
if (input[i] === input[j]) {
should be
if (input[i] === vowels[j]) {

otherwise you get the consonants appearing because it doesn’t check if its a vowel before pushing it to the array.

2 Likes

Thanks! Had this problem as well, but now it’s solved!

Hello everybody! I am stuck on the Whale Talk project and I don’t know why it isn’t working.

The console shows [ ‘i’, ‘u’, ‘u’, ‘u’, ‘u’, ‘u’, ‘u’, ‘a’ ]. I don’t know why there are so many u’s. :cry: :cry:

If anyone could steer me in the right direction that would be amazing!
Thank you,
Alex

let input = 'Hi, Human!';

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

let resultArray = [];

for (let i = 0; i < input.length; i++) {
  for (let j = 0; j < vowels.length; j++) {
if (input[i] === vowels[j]) {
  resultArray.push(input[i]);
}
    if (input[i] === 'e' || input[i] === 'u') {
    resultArray.push(input[i]);
    } 
  }
} console.log(resultArray)

Remember to join the array so you end up with a string.

Thanks for your input. I haven’t got to that bit yet but I realised my problem. My second if statement was in the wrong place!

1 Like