Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Can someone please help me analyse my code and point out my mistake or the place that needs addition.

Your code so far

function maskEmail(email) {
  let atMiddle = email.indexOf("@");
  let userName = email.slice(1, atMiddle - 1);
  let hide = "*"; 
  
  let mailMasked = email.replace(userName, hide.repeat(atMiddle));
  
  return '"' + mailMasked + '"';
  
}
let email = "myeunramcare@gmail.com";
console.log(maskEmail(email));
console.log(maskEmail("apple.pie@example.com"));
console.log(maskEmail("freecodecamp@example.com"));


Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Take a look at this comparison, both strings should have the same number of characters.

console.log("apple.pie@example.com")
console.log(maskEmail("apple.pie@example.com"))
console.log("apple.pie@example.com".length)
console.log(maskEmail("apple.pie@example.com").length)

Okay,
Thank you.
I will get back to you

Thank you
I’ve figured it out.