Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Been trying to figure out what’s wrong with my code, but I just can’t wrap my head around it. The output is exactly the same as required, and yet it fails the tests. Am I doing it wrong?

Your code so far

function maskEmail(email) {
  const address =  email.indexOf("@");
  const slice = email.slice(1, address-1);
  const sliceInitial = email.slice(0, 1);
  const sliceRest = email.slice(address-1);
  const sliceName = slice.replace(slice, "*").repeat(address-1);
  return sliceInitial+sliceName+sliceRest;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Build an Email Masker - Build an Email Masker

Take a close look at the bit of code that repeats the asterisks. Your issue is there…looks like a one-off issue.

Holy cow, looks like the issue really was there. Guess I forgot that counting from the end doesn’t work the same way as if you were to do it from the start.

Thanks a lot for your help!