Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I am getting the required output but still failing the tests.

Your code so far

let email = "freecodecamp@example.com";
let secLastLetBeforeAt = email.indexOf("@") - 1;
let secLet = email.slice(1);
let stars = "*".repeat(secLastLetBeforeAt - 1);


function maskEmail(email) {
  return `"${email[0]}${stars}${email.slice(secLastLetBeforeAt)}"`;
}

console.log(maskEmail(email));

email = "apple.pie@example.com";
secLastLetBeforeAt = email.indexOf("@") - 1;
secLet = email.slice(1);
stars = "*".repeat(secLastLetBeforeAt - 1);
console.log(maskEmail(email));

email = "user@domain.org";
secLastLetBeforeAt = email.indexOf("@") - 1;
secLet = email.slice(1);
stars = "*".repeat(secLastLetBeforeAt - 1);
console.log(maskEmail(email));

email = "info@test.dev";
secLastLetBeforeAt = email.indexOf("@") - 1;
secLet = email.slice(1);
stars = "*".repeat(secLastLetBeforeAt - 1);
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/143.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Hi

A few things to tweak.

User story 2 says that the function should mask the email. The masking happens in variables outside your function. You are only asked to have one global variable.

You have added “” to the returned string which is not required. However, as user story 2 says the function should “append” concatenation is more appropriate than template literals.

Your secLet variable is not used so it can be deleted.

1 Like

Thank you you Legend.

1 Like