Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Hi,
all the codes are running correctly what the results want to be.
But I cannot pass it.. what should I do?
Thank you for your helping in advanced!!

Your code so far

function maskEmail(email){
  const atIndex = email.indexOf('@');
  const userName = email.slice(0, atIndex);
  const firstLetter = email.slice(0,1);
  const lastLetter = email.slice(-1);
  const domain = email.slice(atIndex);

  const userNameLength = userName.length;
  const starRepeat = '*'.repeat(userNameLength);
  const replaceName = userName.replace(userName, starRepeat);
return firstLetter + replaceName + lastLetter + domain;
}

let email = "apple.pie@example.com";
console.log(maskEmail(email));

console.log(maskEmail("apple.pie@example.com"));
console.log(maskEmail("freecodecamp@example.com"));
console.log(maskEmail("info@test.dev"));
console.log(maskEmail("user@domain.org"));

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

Hi and welcome to the community!

Read the error logs carefully. Are your results the same as what the errors say they should be?