Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I have tried both both the methods and my code is correct but somehow it is showing error.

Your code so far

let email = "suryachaudhary.216@gmail.com";
const maskEmail = (email) => {
  let index = email.indexOf('@');
  let back = email.slice(index);
  let front = email.slice(0, index);
  if (front.length <= 2) {
    return console.log(front[0] + "*" + back);
  }
  let a = front[0];
  let b = front[front.length-1];
  let stars = "*".repeat(front.length-2);
  let masked =  a + stars +b + back;
  console.log(masked);
}

maskEmail(email);
maskEmail("apple.pie@example.com");
maskEmail("freecodecamp@example.com");
maskEmail("info@test.dev");
maskEmail("user@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/18.5 Safari/605.1.15

Challenge Information:

Build an Email Masker - Build an Email Masker

Review the user stories:

  1. Call the maskEmail function with the email variable and output the result to the console.

How do you log the function call to the console?

  1. maskEmail("apple.pie@example.com") should return "a*******e@example.com".

What does your function return ?