Message Mixer

Hello All,

in this exercise, for the pigLatin part, why that after the work sky, it doesn’t add the character? Thanks!

my function is like this:

function pigLatin(sentence, character) {
return sentence.split(’ ').join(character + ‘’);

I print below:

console.log(pigLatin(“What is the color of the sky?”, 'oo '));

and the result is:

Whatoo isoo theoo coloroo ofoo theoo sky?


It has to do with being at the end of the sentence. There is nothing beyond to join, so no separator string would be applied.

return sentence.split(' ').join(character + ' ');

We would need to operate on each word in the array, after the split.

s = sentence.split(' ')
// loop through s, modifying each term
return s.join(' ')

You would also have to take into account the full stop at the end of the sentence, or any punctuation within it. That would need to be filtered out, and then put back in.

Hello I understand the logic there is nothing to join after, may i know what’s the “// loop through s, modifying each term” means?

Once we have split the sentence, each word can be isolated without white space. All the strings in the split array will have no spaces.

If there is no punctuation to deal with, all we need is to go through the list and append the character to each word.

Thank you, let me study a bit of what you explained. Thanks!

1 Like