Build an Email Masker - Build an Email Masker

Tell us what’s happening:

My code is long winded but it returns the desired results, it produces the correct outcome for both example emails but i’m stuck as to why it’s not passing on ‘7. Your maskEmail should produce the correct result.’

Thanks for any help!

Your code so far



const maskEmail = (email) => {
  const domainRemoved = email.slice(0, -12);
  const emailSlice = domainRemoved.slice(1, -1);
  const starSlice = emailSlice.replace(emailSlice, '*');
  const repeatStar = starSlice.repeat(emailSlice.length);
  const firstChar = domainRemoved.charAt(0);
  const lastChar = domainRemoved.charAt(domainRemoved.length -1);
  const domainName = '@example.com';
  return `${firstChar}${repeatStar}${lastChar}${domainName}`;
}

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

console.log(maskEmail(email));

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

You have hard-coded a specific domain. Your code is not flexible. For example, can your code handle a gmail.com email address?

Thank you, it wouldn’t work with that, no. I’m struggling with getting everything after the @ sign to not change. I’ve noticed other people using indexOf to do it, but getting my head around it is a challenge. I’ll keep trying…

1 Like

that seems contradictory

but also please do not post your solutions on the forum

1 Like

I’ve solved it now, it took me a while but I now understand the process of using indexOf() to find the number for slicing :grin: Also, it’s great that you don’t show the solution, it makes it way more difficult but I suppose tthat’s the point and I understand it a lot better now.

1 Like

Also, if anyone is struggling, thoroughly read the mozilla documentation for the indexOf, slice and replace methods. Understanding them fully helps a lot.