Pig Latin - Intermediate Algorithms Problem

Tell us what’s happening:
Describe your issue in detail here:

I’m trying to find a way if I can create a function to solve this problem.
I have checked all the requirements except the last one:
[[Should handle words without vowels. translatePigLatin("rhythm") should return the string rhythmay .]]

I can’t seem to find a way to meet this condition, any tips??

  **Your code so far**

function translatePigLatin(str) {

let vowelPosition = findFirstVowel(str);

return vowelPosition > 0
? str.slice(vowelPosition) + str.slice(0, vowelPosition) + "ay"
: vowelPosition === - 1
? str + "ay"
: str + "way";

function findFirstVowel(str) {
  for(let i = 0; i < str.length; i++) {
    if(["a", "e", "i", "o", "u"].includes(str[i])) return i;



  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Pig Latin

Link to the challenge:

What does console.log( findFirstVowel("rhythm") ) show?

1 Like

It shows ‘rhythmway’ instead of ‘rhythmay’

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