Easy Beginner Solution to Pig Latin

Continuing the discussion from freeCodeCamp Challenge Guide: Pig Latin:

Hello everyone,

In the beginning , I was having a bit of trouble in solving this problem. However, after looking at other guides here, I was able to create my version of solution by combining it with my logic. Hope this helps you all:

function checkWord(str) {
let lowerStr = str.toLowerCase();

// Searching for the index from where the first vowel comes in the string
var index = lowerStr.search(/[aeiou]/);

// If there is no vowel in the string and all letters are consonants
if (index === -1) {
    return lowerStr + "ay";
}

// Fulfilling the condition of a word starting with a vowel
else if (index === 0) {
    return lowerStr + "way";
}

//fulfilling the condition of a word when it starts with a consonant
else {
    return lowerStr.slice(index) + lowerStr.substr(0, index) + "ay";
}

}

checkWord(“Classic”);
checkWord(“Dynamic”);
checkWord(“Apple”);
checkWord(“Paragraph”);
checkWord(“schwartz”);
checkWord(“rhythm”);

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Hello @Cody_Biggs ,

My apologies for this. I was not aware of the policy. I saw bunch of learners just posting their solution to help others and I thought that it would help other beginners like me if my solution can also contribute to their learning journey.

If there is any advisory guideline link of what we can post and what we can’t then I would be happy to read and follow it through out my journey here at freeCodeCamp.

Thank you for your advise.

We don’t have it written down so that’s why just inform users when we see it. Mods will remove solutions when we see them on the forum because it doesnt help new coders learn if the solution is just provided for them. Instead we want to make sure that they are the ones who enter the correct code so they know where they went wrong, and not just copy and paste solutions to pass the challenge.

However, there are some who will post their solutions in the contributor section as to suggest a new solution that can be added to the guide link the link you shared here. If you feel like you have a different solution that should be in the guide then you can post it in the contributor section using the spoiler tags. Usually there are a few who check and see if the solution provided can be added to the guide

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.