Build an Email Masker - Build an Email Masker

Tell us what’s happening:

What am I doing wrong. Getting result as asked but why it’s not passing.

Your code so far

function maskEmail(email){
  let index =email.indexOf("@");
  let afterCut = email.slice(index-1);
  let newMail = "*".repeat(index)+afterCut;
  let finalMail = newMail.replace("*", email.at(0));
  return finalMail;
}
let email ="apple.pie@example.com";
console.log(maskEmail(email));
email ="freecodecamp@example.com";
console.log(maskEmail(email));
email="info@test.dev";
console.log(maskEmail(email));
email ="user@domain.org";
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/142.0.0.0 Safari/537.36 Edg/142.0.0.0

Challenge Information:

Build an Email Masker - Build an Email Masker

Hi @abhishekmahato and welcome to our community!

Your function output doesn’t exactly match the requirements.

Try logging your output vs expected output like this for comparison:

let email ="apple.pie@example.com";
console.log("My output:\n" + maskEmail(email));
console.log("Expected output:\n"+"a*******e@example.com")
1 Like