Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I have run the code, verified that I am getting the exact results that the test asks for, yet it will not verify the email addresses to pass me. It is outputting the correct amount of asterisks and displaying the emails correctly. I am not sure what is going wrong. Thank you for any help!

Your code so far

let email = "testing@email.com"

const maskEmail = (email) => {
  let emailSymbol = "@";
  let symbolIndex = email.indexOf(emailSymbol);
  let firstLetter = email[0];
  let maskedEmail = firstLetter + "*".repeat(symbolIndex - 2) + email[symbolIndex - 1] + email.slice(symbolIndex);
 console.log(maskedEmail)
}
maskEmail("apple.pie@example.com");
maskEmail("freecodecamp@example.com");
maskEmail(email);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

Welcome to the forum @randomt4sk

To return something, you need to use a certain keyword.

    1. maskEmail("apple.pie@example.com") should return "a*******e@example.com".
  • Passed:6. maskEmail("freecodecamp@example.com") should return "f**********p@example.com".

To log something, you need to do something.

  • Passed:8. You should log the output of calling maskEmail with email as argument.

Happy coding

Perfect, thank you. Instead of using console.log(), I used the return command. Your advice was spot on, I really appreciate the help!

1 Like