Whale Talk

Hi,

I can not figure out why the result of this doesn’t include an “o” from the first word “Gone”. The result is capturing the e’s and I’s, but not the o. I’ve reviewed the video and looked for the error, but I’m not having any luck.

Ron

The code:

let input = "Gone with the wind";
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]) {
      if(input[i] === "e") {
        resultArray.push('ee');
      } else if(input[i] === "u"){
        resultArray.push('uu');
      } else {
        resultArray.push(input[i]);
      }
    }
  }
}
console.log(resultArray.join('').toUpperCase());

Result: EEIEEI

Hello, @ronhir

if ( 'o' === ' o') will evaluate to false.

2 Likes

Man little typos like that drive me insane. Its like I have to find typos way more often than I messed my code up. Although honestly I have been struggling a bit with JS. Those little typos cost me a lot of time though sure wish it was a little more forgiving .

2 Likes

Well, you’re not alone. I make typos in code all of the time. Hopefully with practice you’ll know where to start looking for the mistakes, and save a little time that way. The error messages are actually quite helpful. Happy coding!

Wow, when I first saw this response I thought I understood so I went back and having messing with the code most of day…still not working. It took me awhile to notice the extra space. Ugh! It is amazing how quickly to found the error! I was going over and over the loops thinking I was doing something wrong. So often it turns out to tiny typo…must remind myself to look for those first! LOL. Thanks for the help.

1 Like

uhhh, “you” found the error! :joy: