Hello I need some help!

Hello, I need some help! Here’s the description. I’ve been trying to figure it out but there’s some tests I don’t pass!

Pig Latin

Pig Latin is a way of altering English Words. The rules are as follows:

  • If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add ay to it.

  • If a word begins with a vowel, just add way at the end.


function translatePigLatin(str) {
let regex = /^[^aeiou]/i;
let consonant = str.match(regex); 
if(consonant === null) {
  str += 'way'; 
} else if(consonant !== null) {
  str = str.split(""); 
  let final = str.shift(); 
  str.push(final); 
  str = str.join('');
  str += 'ay';  
} 
return str; 
}

translatePigLatin("california")
translatePigLatin("algorithm")

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36

Challenge: Pig Latin

Link to the challenge:

How are you handling ‘consonant clusters’, which is to say multiple consonants before the first vowel?

1 Like