Intermediate Algorithm Scripting - Pig Latin

Tell us what’s happening:
Describe your issue in detail here.
My code works fine on all the user tests except for this one

Should handle words where the first vowel comes in the middle of the word. translatePigLatin(“schwartz”) should return the string artzschway.
// tests completed
Your code so far

function translatePigLatin(str) {
  let string = str.split(""),
      vowels = ["a", "e", "i", "o", "u"],
      newStr = [],
      include = 0;

  for (let i=0; i<string.length; i++) {
  if (vowels.includes(string[0])) {
    return string.join("")
  } else if (!vowels.includes(string[0])) {
    for (let i=0; i<string.length; i++) {
      if (!vowels.includes(string[i])) {
        include += 1
    if (include === string.length) {
      return string.join("")

  for (let i=newStr.length+1; i>=0; i--) {
    if (!vowels.includes(newStr[i])) {
      let letter = newStr.shift()
  return newStr.join("")










Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Pig Latin

Link to the challenge:

What’s your question? What did you try so far? Do you have some ideas what exactly is causing the wrong result?

1 Like

I wanted to check if there’s a vowel in the middle of the word so i modified the code after adding to include and to check if the length of the letters that got pushed is equal to the (length of string - include )if so i tried to puah “way” but that didn’t work so i deleted that line and here we are
how can i do that

Could you explain how would that work?

From what I understand, if the number of pushed non-vowel letters is the same as the length of string, then all letters in string are consonants. Otherwise there might be vowel somewhere in the string, but position of it is not certain. It can be at the end, it can be somewhere in the middle.

If number of non-vowel letters is equal to the length of atring mines(-) the number of non-vowel letters then it will push “way” and return the string i think i didn’t put condition to make the loop stop when it finds a vowel

That doesn’t seem to be right. Isn’t way to be added only when word starts with vowel?

I solved it it turned out to be the letter “w” that confused me i thought it was part of the “way”

My code should handle the word schwartz so i need to push all the letters before the vowel the letter “w” confused me i thought the requirement was to add “way” if the vowel is in the middle of the word

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