Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Poor preparation for such a complex problem. The only way to solve this at this point in my training is to review successful results and try to understand what’s happening.

Your code so far

function maskEmail(email) {
  
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build an Email Masker - Build an Email Masker

Start small.

You’ve created a function :white_check_mark: Perfect first step.
It takes email as an argument :white_check_mark:

Next,

  1. Inside the function, you should mask the email and append the domain name to it. Remember that you can use methods like slice, repeat, indexOf or even replace to help you.

This is a bit more complicated. Break it down into simpler steps.

  1. Inside your function log email to console so you can see what’s coming in
  2. call your function with test input so you can confirm it’s working so far
  3. try using slice in the console.log() that you’ve added to modify email

Search for “javascript slice” if you need a reminder on how to use it.

Tell us what’s happening:

I’ve already previously stated that the preparation for such a complex problem at this point in the training was lacking. I had to google results and use ChatGPT to show me the solution and how it was doing this. At this point I think I understand everything except “username[0]”. I’ve tried to delete or change the “[0]” and it does strange things that I can’t comprehend. I’ve deleted the return since you don’t want a result posted. Please help me understand what the “[0]” is doing.

Your code so far

function maskEmail(email) {
  let atIndex = email.indexOf("@");
  console.log(atIndex);
  let username = email.slice(0, atIndex);
  console.log(username);
  let domain = email.slice(atIndex);
  console.log(domain);

  let maskedUsername =
    username[0] +
    "*".repeat(username.length - 2) +
    username[username.length - 1];
    console.log(maskedUsername);


}

let email = "apple.pie@example.com";
console.log(maskEmail(email));
email = "freecodecamp@example.com";
console.log(maskEmail(email));
email = "info@test.dev";
console.log(maskEmail(email));
email = "user@domain.org";
console.log(maskEmail(email));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build an Email Masker - Build an Email Masker

I figured it out. domain[0] is pulling the first letter from the domain string.

1 Like

please do not create multiple posts for the same challenge

At some point here always must be a leap in difficulty that will challenge you.

You might need to experiment or look up documentation outside freeCodeCamp. Experimentation and research are key programming skills.

The challenge even mentions to use some methods:

Remember that you can use methods like slice, repeat, indexOf or even replace to help you.

What knowledge do you think you were lacking?