Build an Email Masker - Build an Email Masker

Tell us what’s happening:

My code is outputting correctly. There are no extra characters anywhere. I’ve used all the suggested methods: repeat(), replace(), slice() but the results are still not accepted by the lab.

Your code so far

function maskEmail(email) {

  const hide = "*";
  const middleText = email.slice(1, email.indexOf("@") - 1); //pple.pi
  const convert = email.replace(middleText, hide.repeat(middleText.length));

  console.log(convert);

}

const email = "apple.pie@example.com";

maskEmail("apple.pie@example.com"); // a*******e@example.com
maskEmail("info@test.dev"); // i**o@test.dev
maskEmail("user@domain.org") // u**r@domain.org

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15

Challenge Information:

Build an Email Masker - Build an Email Masker

What your function returns? Try wrapping the test calls with the console.log to check that, ie:

console.log(maskEmail("user@domain.org"));

Thank you for the suggestion, I tried that but it still won’t accept it. It comes back as undefined under the output.

the console.log is not the solution, the console.log is to show you that the function returns undefined, and now that you know that you can work on fixing it

Let me know if I’m going in the right direction but it seems “email” is not declared first right? So trying to call the indexOf() function shoot back in error due to that? Sorry this is stumping me so bad.

Do you remember what causes a function call to display undefined?

Okay I think I’m starting to get it. Everything seems to be accepting except step number 2. I’ve tried logging it with (email) as the argument but it won’t take.

if you need more help please post your updated code

function maskEmail(email = "apple.pie@example.com") {

  const hide = "*";
  const middleText = email.slice(1, email.indexOf("@") - 1); //pple.pi
  const convert = email.replace(middleText, hide.repeat(middleText.length));

  return convert;
}

let email = "apple.pie@example.com";

console.log(maskEmail(email));

why are you giving a default value to email parameter?

Pointing that out worked! Thank you for your help and patience!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.