Build an Email Masker - Correct output but criteria not met

I know people have posted about this already but I don’t see how this isn’t passing the criteria.

function maskEmail(email) {

  let pos = email.indexOf("@");
  let maskedLength = pos - 2;

  let begin = email.slice(0, 1);
  let end = email.slice(pos);

  let replace = "*";
  let replaced = replace.repeat(maskedLength);

  let finishedEmail = begin + replaced + end;

  return finishedEmail;

};

let email = "apple.pie@example.com";

console.log(maskEmail(email));

email = "freecodecamp@example.com";

console.log(maskEmail(email));

Please post a link to the step.

What is the required output? I thought it was supposed to have 2 cleartext letters?

maskEmail("freecodecamp@example.com") should return "f**********p@example.com".

Yea, you don’t exactly match the required output. Look at the letters around the @

oh I see what you’re saying. I’ll fiddle with it

This seems to get the right output but same criteria result EDIT: no this adds an extra “*”

function maskEmail(email) {

  let pos = email.indexOf("@") - 1;
  let maskedLength = pos;

  let begin = email.slice(0, 1);
  let end = email.slice(pos);

  let replace = "*";
  let replaced = replace.repeat(maskedLength);

  let finishedEmail = begin + replaced + end;

  return finishedEmail;

};

let email = "apple.pie@example.com";

console.log(maskEmail(email));

email = "freecodecamp@example.com";

console.log(maskEmail(email));

Okay this worked

function maskEmail(email) {

  let pos = email.indexOf("@");
  let maskedLength = pos;

  let begin = email.slice(0, 1);
  let end = email.slice(pos - 1);

  let replace = "*";
  let replaced = replace.repeat(maskedLength - 2);

  let finishedEmail = begin + replaced + end;

  return finishedEmail;

};

let email = "apple.pie@example.com";

console.log(maskEmail(email));

email = "freecodecamp@example.com";

console.log(maskEmail(email));```
1 Like

Passed solution.

MOD EDIT: Solution removed.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.