Clean up my Email Masker

Hey all,

after fumbling around all day I actually managed to pass the assignment of “Build an Email Masker” but I feel like I Frankensteined the whole thing together in a chaotic way.

Can you give me tips how to clean this up, or is it actually acceptable like this?

Thank you for your help :slight_smile:

const email = “apple.pie@example.com”;
function maskEmail (email) {
let indexAt = email.indexOf(“@”);
let name = email.slice(1, indexAt -1);
let nameLength = name.length;
let star = “*”;
let maskedName = name.replace(name, star.repeat(nameLength));
let firstLetter = email.slice (0, 1);
let lastPart = email.slice (1 + nameLength);
return firstLetter + maskedName + lastPart;
}

maskEmail(email);

console.log(maskEmail(email))

Hi there,

I’ve moved your topic to the Code Feedback category and blurred your code, so it doesn’t spoil the challenge for those who haven’t done it yet.

If it works, it’s acceptable. If you like you can go back and try to make it cleaner, by reducing the variables, finding another method to do it.

Are all of these variables really necessary?

1 Like

… it turns out no ^^’!

1 Like