Build an Email Masker - Build an Email Masker

Tell us what’s happening:

What is the problem in my code with case 9? It passes all the test except this one

Your code so far

function maskEmail(email){
  let slicepoint = email.indexOf("@");
  let mask = email.slice(0,slicepoint-1);
  let leftover = email.slice(slicepoint-1,email.length);
  let maskFchar = mask[0];
  let regEx = /[a-z.]/g;
  let masked = mask.replace(regEx,"*");
  masked = masked.replace("*",maskFchar);
  
  return masked + leftover;

}
let email = "apple.pie@example.com";

console.log(maskEmail(email));

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

Welcome to the forum @maksimdimmitrov

Try masking:

Apple.pie@example.com

Happy coding

Well i tried masking Apple.pie@example.com and with the previous version of my code the regex didnt detect capital chars. Ive now fixed the regex to include capital letters and managed to masked the address you sent me successfuly but I still get that error.

How about other characters?

bill&ted@example.org

Happy coding

Well, I think I get where this is going. I fixed my regex pattern again and I’ve included some other special characters just in case,but still i cannot pass the test.
My regex looks like this now - let regEx = /[a-z.A-Z&$?;|]/g;

Try +

Happy coding

1 Like

Thank you very much for the feedback and the help! I’ve added the + sign in the regex and it let me pass the test

1 Like