Help with my javaScript "Whale Talk" project


#1

I’m a beginner with JS and i’ve been logging this code but i seem to be getting a syntax error and i don’t know where it went wrong :

const input = ‘I love Whale Talk.’;

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

let resultArray = ;

for (let inputIndex = 0; inputIndex < input.length; inputIndex++;) {
for (let vowelIndex = 0; vowelIndex < vowels.length; vowelIndex++;) {
if (input[inputIndex] === vowels[vowelIndex]) {
returnArray.push(input[inputIndex]);
}
}
if (input[inputIndex] === ‘e’ || input[inputIndex] === ‘u’) {
returnArray.push(input[inputIndex]);
}
}

console.log(resultArray);

This is the link ???
https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-loops/projects/whale-talk


#2

Suggestion: each time you post a question, paste in the URL to the lesson. This allows us to go back and look at the entire lesson objective.


#3

Thanks, I’ve added it


#4

Hello, I 've noticed that firts you must make sure that the letters in the string are not capital letters by using this piece of code right below 'const input ':

input = input.toLowerCase();

What is more you’ve got a bug after ‘if statement’:
you push the result to the const resultArray = (you don’t have the returnArray) :slight_smile: so instead of this:

returnArray.push(input[inputIndex]);

try this:

resultArray.push(input[inputIndex]);

Let me know if this works :slight_smile:


#5

Thanks for your help, but i’m still getting syntax error.


#6

Ok, I have also noticed that ‘const input’ should be changed to ‘let input’ (you change it to lowerCase later on)
Also - no need for the semicolon at the end of for loop

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

shoul be

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

also here:

for (let vowelIndex = 0; vowelIndex < vowels.length; vowelIndex++;) 

should be

for (let vowelIndex = 0; vowelIndex < vowels.length; vowelIndex++) 

if you want to console log the final whale message you should console log this:

console.log(resultArray.join('').toUpperCase())

Let me know if that works :slight_smile:


#7

Extra Study

Ignore this post for the time being, only bookmark it and return when you reach the unit on iterators.

input = "You Are All Wee Gillis";
vowels = ['a','e','i','o','u'];
whaleTalk = [];
input.split('').filter(v => vowels.includes(v.toLowerCase())).forEach(x => {
  if (x === 'e' || x === 'u') {
    whaleTalk.push((x + x));
  } else {
    whaleTalk.push(x);
  }
});
console.log(whaleTalk.join('').toUpperCase())    //  OUUAEEAEEEEII

Don’t try to make sense of it, just now. You can see where our learning about the for loop (which is an iterator, in fact) will eventually lead.


#8

Thank you, it works.


#9

Super! :slight_smile: Good luck!


#10

2 posts were split to a new topic: Coul you take a look at my code bellow?