Build an Email Masker

Tell us what’s happening: can I write it in a better way? Or could you plz give some suggestions?

Your code so far

function maskEmail(email){
  let len = email.slice(1,email.indexOf("@"));
  const length = len.length-1;
  email = email.replace(email.slice(1,email.indexOf("@")-1),"*".repeat(length));
  return email;
}
 let email = "apple.pie@example.com";
 console.log(maskEmail(email)) ;
 maskEmail("freecodecamp@example.com");
 maskEmail("info@test.dev");
maskEmail("user@domain.org");
maskEmail("com.user@example.com");
maskEmail("test.net@netnet.net");
maskEmail("testtest@domain.com");

Lesson URL (copy - paste from your browser’s address bar)

Hi @korinikita85

Maybe rename the variables so others and yourself have a better idea of their purpose.

Happy coding

ok, thank you very much for your feedback

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.