Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I have been staring at this code for a while and I can’t tell why its returning an extra asterisk, nothing stands out to me as being particularly out of place. Can someone give me some pointers as to what specifically I need to alter? Cheers! :slight_smile:

Your code so far

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

function maskEmail(email) {
  const address = email.indexOf("@")-1;
  const slice = email.slice(1, address);
  const mask = "*"; 
  const replace = email.replace(slice, mask.repeat(address));
  return(replace); 
}
console.log(maskEmail(email))

email = "freecodecamp@example.com";
console.log(maskEmail(email));
email = "info@test.dev";
console.log(maskEmail(email));
email = "user@domain.org"
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/146.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Welcome to the forum @Lucas_Haddy !

Does the length of slice equal address?

And I strongly recommend against using method names as variable names (e.g. slice, replace).

Happy coding!

I figured it out eventually thanks to your minor pointer! Thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.