Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I am getting the desired result but test not passing. Please help

Your code so far

const maskEmail = email => {
  const str1 = email.slice(0, -(email.length - 1));
  const str3 = email.slice(-13);
  const str2 = email.slice(1, -13);
  let replacementString = "*";
  const repeatReplacementString = replacementString.repeat(str2.length);
  const replacedPart = str2.replace(str2, repeatReplacementString);
  return str1 + replacedPart + str3;
}

let email = "apple.pie@example.com";
console.log(maskEmail("apple.pie@example.com"));
email = "freecodecamp@example.com";
console.log(maskEmail("freecodecamp@example.com"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

1 Like

test 7 is also checking for other emails. Your function doesn’t work for example for johnappleseed@email.com

Ilenia ?

okay I understood, I will modify code but I need to think how to do it.

Now I am getting the correct masking for @email.com also. But my 8th test not passing, Please help

use the email variable in the logging

Thank you, test Passed