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~

1 Like

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: