Build an Email Masker - Build an Email Masker

Tell us what’s happening:

ooh wee this # 7 is tough… the console is producing desired outcome but it does not pass.

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(email));
email = "freecodecamp@example.com";
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/136.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

What happens when somebody has email in different domain than example.com?

i changed it to google and it applied it to the console. it changed but it did not pass. can you refer me to a specific lesson?

You need to find out what emails the tests are sending to your function. Add a console.log as the first line of your function to see the input email.

Take a look at the one in description - "myEmail@email.com"

you guys take this “riddle me this” answers to another level. Okay… i put in the @email.com and it is not working properly i see it. Just gotta figure out how to fix it. Thank You…

You are using hard-coded “magic” numbers in your slice(). Try to figure out how you can mask email addresses without using those.

still can not get this. yall keep on hinting but. I’m not getting it… trying to learn and not guess my way through. i have googled and w3 schools and just not working. where are the videos or lessons on how to do this??? This one is beyond frustrating.

Can you please share your updated code?

these labs are there to help you develop problem solving skills, guided exercises do not help with that. It’s hard now, with practice it is going to be easier

Try breaking down this problem in smaller steps

it could be, figure out where the @ is as that is not going to be changed
figure out how to replace a character with *, and other steps