Build an Email Masker - Build an Email Masker

Tell us what’s happening:

My solution is correct but it is not passing the test.

Your code so far

const maskEmail = (email) => {
    let hide = "*";
    const textFinder = email.slice(0, ( email.indexOf("@") ));
    const emailCheck = email.slice(email.indexOf("@")); 
    const showFirstandLast = textFinder.slice(1, ( email.indexOf("@") - 1));

    const textToHide = textFinder.replace(showFirstandLast, hide.repeat(textFinder.length))    

    return textToHide + emailCheck;
}

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/131.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

check the length here of the output and of the string console.log(email.length, maskEmail(email).length), they are different lengths, you added extra characters.
We can also see that putting them one above the other:

console.log(email);
console.log(maskEmail(email));

it shows:

freecodecamp@example.com
f************p@example.com

you have added two extra characters to the mail

1 Like

Thank you so much for the debugging idea, I found the problem now!