# simple pig latin codewars kata problem

**URL:** <https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500>\
**Category:** Uncategorized\
**Created:** [January 25, 2023, 7:43am UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500 "2023-01-25T07:43:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)\
**Post date:** [January 25, 2023, 7:43am UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/1 "2023-01-25T07:43:43Z")

</div>

I’m doing this kata.

> **[Training on Simple Pig Latin](https://www.codewars.com/kata/520b9d2ad5c005041100000f/train/javascript)**
>
> Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

```auto
function pigIt(str) {

const words = str.split(" ");

for (var i = 0; i < words.length; i++) {

if (words[i] === "!") {

return "!";

}

var firstLetterSliced = words[i].slice(0, 1);

var remainingLetterSliced = words[i].slice(1, words[i].length);

return (remainingLetterSliced + firstLetterSliced + "ay");

}

}

pigIt('Pig latin is cool'); // igPay atinlay siay oolcay

```

My code isn’t passing a test. Please help fix the issue.

 ![](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/c/f/cff7d797c5d5b098d0b84faa718bd23b4ccd96a1.png)

It works as expected so why is it not passing the tests?

---

<div class="post-metadata">

**Author:** ![PAEz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/paez/32/19607_2.png) [@PAEz](https://forum.kirupa.com/u/PAEz)\
**Post date:** [January 25, 2023, 8:41am UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/2 "2023-01-25T08:41:27Z")

</div>

Your only processing the first word. You’ve done it right but you need to do it to every word, rebuild the string and return it. If you thought you where doing every word then check your for loop and where the return is. I could tell you more but then the exercise would be pointless 😜

---

<div class="post-metadata">

**Author:** ![polaryeti](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/polaryeti/32/19283_2.png) [@polaryeti](https://forum.kirupa.com/u/polaryeti)\
**Post date:** [January 25, 2023, 9:53am UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/3 "2023-01-25T09:53:43Z")

</div>

please tell more…🙂 It won’t be pointless.

---

<div class="post-metadata">

**Author:** ![PAEz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/paez/32/19607_2.png) [@PAEz](https://forum.kirupa.com/u/PAEz)\
**Post date:** [January 25, 2023, 12:12pm UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/4 "2023-01-25T12:12:03Z")

</div>

Im not sure how to give you more help without giving you the answer.  
Your function is supposed to return…  
‘igPay atinlay siay oolcay’  
…but instead you returned…  
‘igPay’  
…why? Your function is returning a result before doing all the work, why? You know it did one word right, why not the rest? First I would put a console.log(words) after splitting str to see what you get, which would be [“Pig”, “latin”, “is”, “cool”] so you know thats right and you got all the words. Your for loop is told to do all the words so thats not it. The second word isnt a “!” so it shouldnt return there, but I would be asking my self why would I want the result of this function to be “!” at any point…If a word is “!” then the returning result will be “!”, is that what you want?. The last 3 lines successfully split the word and put it back together again, the result showed us that but the last of those 3 lines starts with a return so the function is going to stop what its doing and return the result of the last line, but thats not what you want. So instead maybe you should store that word somewhere and not return so the for loop can continue and process the rest of the words. You could put the result in another variable, say “result” and keep adding to that to build the resulting string. Or, since words is an array already with the right amount of words just put the result back in to words[i] and join that array later. When you hit “!” you dont want to return that but ignore it, so instead of returning you could `continue`. Look it up, continue in a for loop will make it skip this rest of the code in the for loop and got to its next iteration. Then after the for loop `words` should be filled with the modified words so you can `join` the array with a space and return that.  
Ok, thats my attempt at giving you an answer without giving you code 😜

EDIT: If you want something to aim for, using modern stuff I got this down to one line of code no hassle. Thanks for reminding me of this place, thinking I might do a bunch again but this time try to force myself to use modern stuff…Im still very much a for loop guy, years of muscle memory to reprogram. Oh, and if you ever get to the point your just want to see a code answer, say and Ill give you a for loop version.

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [January 25, 2023, 10:14pm UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/5 "2023-01-25T22:14:34Z")

</div>

If you want practice on a similar exercise that still introduces similar concepts with a video explanation, then this may be right up your alley as well:

> **[The Devowelizer Coding Challenge](https://www.kirupa.com/html5/the_devowelizer.htm)**
>
> Test your ability to work with strings in this fun exercise where your goal is to remove all vowels from some text.

---

<div class="post-metadata">

**Author:** ![PAEz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/paez/32/19607_2.png) [@PAEz](https://forum.kirupa.com/u/PAEz)\
**Post date:** [January 26, 2023, 7:41am UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/6 "2023-01-26T07:41:37Z")

</div>

You keep suggesting things to try and I dont bother, so I did this one.  
Not comfortable using regex’s so I just used normal stuff.

```auto
  let devowelize = (str) => [...str].filter(letter => !'iouae'.includes(letter.toLowerCase())).join('');
  devowelize("Kirupa Chinnathambi");

```

Do I get a cookie? 😜

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [January 26, 2023, 6:07pm UTC](https://forum.kirupa.com/t/simple-pig-latin-codewars-kata-problem/656500/7 "2023-01-26T18:07:00Z")

</div>

Even better. You get a shiny badge 🙂

 ![image](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/4/b/4ba1f0c84cad813f01483b35d137f12f79bc174c.png)
