Build an Email Masker - Build an Email Masker

Tell us what’s happening:

All the tests work except apple.pie. The masked email seems to retain the “e” at the end of it. Should I create a special case where an email address has an “e” at the end?

Your code so far

function maskEmail(email) {
  const toAt = email.indexOf("@");
  const emailName = email.slice(0, toAt);
  return emailName[0] + "*".repeat(emailName.length-1) + "@" + email.slice(toAt+1);
}

let email = "apple.pie@example.com";
console.log(maskEmail(email));
console.log(maskEmail("freecodecamp@example.com"));
console.log(maskEmail("info@test.dev"));
console.log(maskEmail("user@domain.org"));
// apple.pie@example.com
// a********@example.com
// a*******e@example.com ?????????????
// freecodecamp@example.com
// f***********@example.com
// info@test.dev
// i***@test.dev
// user@domain.org
// u***@domain.org

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5.2 Safari/605.1.15

Challenge Information:

Build an Email Masker - Build an Email Masker

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-email-masker/66b205e6eacba4c4e54ea434.md at main · freeCodeCamp/freeCodeCamp · GitHub

are you sure?

you are asked to mask the email from myEmail@email.com to m*****l@email.com

note last letter before @

there is no way for that letter to be preserved with this

I stared at that for 10 solid minutes and did not see it. Thank you for your time.