So I passed the lab with this code however I’d like help understanding why the code initially adds an extra two asterisks to the email censorship. I want to know since there’s definitely a better way of doing this rather than just cutting out whatever extra pieces get added in somehow.
Your code so far
function maskEmail(email) {
let splitPart = email.indexOf("@");
let sliced = email.slice(1, (splitPart -1))
let hide = "*";
let hiddenmail = email.replace(sliced, hide.repeat(splitPart -2));
return hiddenmail
}
let email = ("apple.pie@example.com")
console.log(maskEmail(email))
maskEmail("freecodecamp@example.com");
maskEmail("info@test.dev");
maskEmail("user@domain.org")
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Sorry, here was my initial code that added the extra asterisks. The only difference was instead of having a -2, I initially only had a -1 after splitPart