Build an Email Masker - Build an Email Masker

Tell us what’s happening:

function maskEmail(email){

let endIndex = email.indexOf(“@”);

let maskedEmail = email.slice(1,endIndex);
let maskedEmailLen = maskedEmail.length-1;
let asterik = “*”.repeat(maskedEmailLen);

return email.replace(maskedEmail,asterik);

}

const email = “freecodecamp@example.com”;
console.log(maskEmail(email));

this is my code which is working fine still test cases are not passing

Your code so far

function maskEmail(email){

let endIndex = email.indexOf("@");

let maskedEmail = email.slice(1,endIndex);
let maskedEmailLen = maskedEmail.length-1;
let asterik = "*".repeat(maskedEmailLen);

return email.replace(maskedEmail,asterik);

}

const 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/142.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Here are some troubleshooting steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the first failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

Welcome to the forum @kumarxxx242424

Are you sure you need to unmask just one character?

Happy coding

[mod edit - solution removed]

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like