Hello there, can somebody explain to me why do we write consonants != null
?
I tried: consonants != [""]
but it doesn’t work. Why is it just null and not an empty string or something.
Below I added a “SELF ATTEMPT” code which I tried before getting hints. I tried converting the result of .match() to a string to get the length for .slice(). Is this wrong. I’m just curious if it is possible to do it this way. Would be great if somebody can give advice on improvement/advice on what to be avoided. Thanks in advance! Really enjoying this community ^^
**Your code so far**
function translatePigLatin(str) {
var regexVowel = /^[^aeiou]+/;
let consonants = str.match(regexVowel);
return consonants !== null
? str
.replace(consonants, "")
.concat(consonants)
.concat("ay")
: str
.concat("way");
}
translatePigLatin("eight");
SELF ATTEMPT
var regexVowel = /^[^aeiou]+/;
var front = str.match(regexVowel);
front = front.toString();
console.log("toStr: " + front);
if (front === str && front !== "") {
return str.concat("ay");
} else if (front !== str && front !== "") {
let length = front.length;
return str.slice(length) + front + "ay";
} else {
//str + "way";
}
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
Challenge: Pig Latin
Link to the challenge: