Following code showing "Cannot read property '0' of null"
function translatePigLatin(str) {
let x=["a",'e','i','o','u','A','E','I','O','U'];
//let x=["aeiouAEIOU"];
let regex=/[aeiou]/ig;
console.log(str.match(regex));
var vowelIndice = str.indexOf(str.match(regex)[0]);
if (str[0].match(regex)) {
return str + 'way';
}
//console.log(vowelIndice);
return str.match(regex)===null?str+"ay":str.substr(vowelIndice) + str.substr(0, vowelIndice) + 'ay';
console.log(translatePigLatin("glove"));
Where am i wrong..?
You might be missing a closing bracket }
at the end of your function. Try to add }
after your outer return
statement.
still it is showing same error
str.indexOf(str.match(regex)[0])
If str.match
returns null, then it does not have any indices to access