Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Running my code results in “9. Your maskEmail should produce the correct result.” But I have checked all the other boxes. What am I missing?

Your code so far

let email = "myEmail@email.com";
function maskEmail(email){
   const emailFirstLetter = email.slice(0,1);
   const emailToBeMasked = email.slice(1 , email.indexOf("@") - 1);
   const replace = emailToBeMasked.replaceAll(/[a-zA-Z.]/g,"*");
   const emailLastLetter = email.slice(email.indexOf("@") - 1, email.indexOf("@"));
   const emailAdd = email.slice(email.indexOf("@"));
   email = emailFirstLetter + replace + emailLastLetter + emailAdd;
   return email;
}
console.log(maskEmail(email));
console.log(maskEmail("apple.pie@example.com"));
console.log(maskEmail("freecodecamp@example.com"));
console.log(maskEmail("info@test.dev"));
console.log(maskEmail("user@domain.org"));

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

Challenge Information:

Build an Email Masker - Build an Email Masker

Welcome to the forum @random1234

I see your code is replacing each letter a with a *.

Try logging the following code:

console.log(maskEmail("us-er@domain.org"));
console.log(maskEmail("us1er@domain.org"));

Happy coding

u*-*r@domain.org
u*1*r@domain.org
this was the output, so i added “0-9-” to the regex to get the results of

u***r@domain.org
u***r@domain.org

but it still comes up with:

// running tests
9. Your maskEmail should produce the correct result.
// tests completed
// console output
a*******e@example.com
f**********p@example.com
i**o@test.dev
u**r@domain.org
u***r@domain.org
u***r@domain.org

But it still comes up with :

// running tests
9. Your maskEmail should produce the correct result.
// tests completed
// console output
a*******e@example.com
f**********p@example.com
i**o@test.dev
u**r@domain.org
u***r@domain.org
u***r@domain.org

What about:

  • bill+ted@domain.org
  • bill&ted@domain.org

Happy coding

I gotcha so all special characters are needed for the completion added .*[\¬\!\"\£\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\@\~\<\>\?\[\]\;\'\#\,\.\/\\\| to the code to make it work

I don’t think those are all characters allowed in email addresses tho, so now it may be too much, but if it works you are doing great