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++) {
newStr.push(string[i])
}
if (vowels.includes(string[0])) {
string.push("way")
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) {
string.push("ay")
return string.join("")
}
}
for (let i=newStr.length+1; i>=0; i--) {
if (!vowels.includes(newStr[i])) {
let letter = newStr.shift()
newStr.push(letter)
}
}
newStr.push("ay")
return newStr.join("")
}
console.log(translatePigLatin("consonant"));
console.log("\n")
console.log(translatePigLatin("algorithm"))
console.log("\n")
console.log(translatePigLatin("rhythm"))
console.log("\n")
console.log(translatePigLatin("glove"))
console.log("\n")
console.log(translatePigLatin("schwartz"))
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 11; Nokia 3.4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Mobile Safari/537.36
Challenge: Intermediate Algorithm Scripting - Pig Latin
Link to the challenge: