Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I don’t know what I am doing wrong here, why isn’t it saying task complete? Code seems to work as asked.

Your code so far

function maskEmail(email) {
  //slice part before email.com
  const emailTail = email.slice(email.indexOf('@'));
  const emailHead = email.slice(0, email.indexOf('@'));
  let masked = emailHead;

for (let i = 0; i < emailHead.length; i++) {
  if (i != 0 || i != email.length) {
    masked = masked.replace(emailHead[i], '*');

  }

}

return emailHead[0] + masked + emailHead[emailHead.length - 1] + emailTail;

}

const email = "info@test.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/138.0.0.0 Safari/537.36 Edg/138.0.0.0

Challenge Information:

Build an Email Masker - Build an Email Masker
https://www.freecodecamp.org/learn/full-stack-developer/lab-email-masker/build-an-email-masker

Have you looked at the failing tests and compared your function ouput with the expected output?

For instance, for one of the failing tests, try reassigning your email variable and then log your function output and the expected output like this:

const email = "apple.pie@example.com";
console.log(maskEmail(email));
// expected output
console.log("a*******e@example.com")

It looks like you are adding more asterisks than what is expected, so look at that bit of code.

yeah, just adjusted my for loop, to cover only the indexes that i need