Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I am seeing the expected output and all tests pass except for test 7 which makes no sense to me.

Your code so far

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

function maskEmail(email) {
  const atIndex = email.indexOf("@");
  const domain = email.slice(atIndex);
  const username = email.slice(0, atIndex);

  const firstChar = username[0];
  const lastChar = username[username.length - 1];
  const middle = username
    .slice(1, -1)
    .replace(/[a-zA-Z.]/g, "*");
  return firstChar + middle + lastChar + domain;

}

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/137.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Hi @derocherdavid and welcome to our community!

Are you sure you have the correct number of asterisks?
This is the expected output for the email above:

console.log("a*******e@example.com")

What happens if the email address is a0l@aol.com or koai-2422@gmail.com. Does your code handle that as expected?