Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I don’t understand how to do the rest of the steps after step 4. This should really have another workshop for stuff like this before a lab like this. It’s hard to know what to do if we don’t see it properly before hand.

Your code so far

function maskEmail(email) {let arobasePosition = email.indexOf("@");
let wordToSlice =email.slice(1, arobasePosition);
let wordToSliceCharCount = wordToSlice.lenght - 1;
let replacedChar= email.replace(wordToSlice, "*".repeat(wordToSliceCharCount));};

let email= "apple.pie@email.com";
console.log(maskEmail(email));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0

Challenge Information:

Build an Email Masker - Build an Email Masker

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-email-masker/66b205e6eacba4c4e54ea434.md at main · freeCodeCamp/freeCodeCamp · GitHub

Currently, your function is not returning anything.

Maybe try adding some logs within the function so you can see what your code is doing after each line.

oh console.log. I’ll tried that. Although I’m not sure how to do that.

Within the function, add console.log(wordToSlice) under that line of code. And repeat a log like that for each line to help you debug.

oki. I’ll try that. :slight_smile: Thank you for the help.

now I’m stuck again.

function maskEmail(email) {let arobasePosition = email.indexOf("@");
let wordToSlice =email.slice(1, arobasePosition);
console.log(wordToSlice);
let wordToSliceCharCount = wordToSlice.lenght - 1;
console.log(wordToSliceCharCount);
let replacedChar= email.replace(wordToSlice, "*".repeat(wordToSliceCharCount));
console.log(replacedChar);};

let email= "apple.pie@email.com";
console.log(maskEmail(email));

Please analyze your logs. Is wordToSlice what you expect it to be? If not, make an adjustment so it is. Then move on to the next log, etc.

I think this lab is way too hard. I’m gonna try tomorrow. but still don’t get how to get the results I want that’s the problem. if there was more specific help in the lab it would help. I know we did see everything but I have no idea how to suggest freecodecamp had another workshop for smth like this.

what steps would you take to hide an email like that if you had to do it manually?

Hi @christinewho2,

You are so close! And I really like your approach…going directly after the bit that needs to be changed.

If you make one small adjustment to the line of code that creates wordToSlice and make another small correction in your code to get wordToSliceCharCount (after fixing the typo), you’ve got it!

You can check that wordToSliceCharCount is what you want by counting the asterisks in what Test #5 says your code should return.

Just make sure your function returns the final masked email.

Hope that helps…

Happy coding

I don’t see any typo?

nvm found it and now I don’t know how to do it to actually make it stick.

probably have to with no console.log or something. or maskEmail(email) something. Also might need to use some literate or smth.

function maskEmail(email) {let arobasePosition = email.indexOf("@");
let wordToSlice =email.slice(1, arobasePosition);
console.log(wordToSlice);
let wordToSliceCharCount = wordToSlice.length - 1;
console.log(wordToSliceCharCount);
let replacedChar= email.replace(wordToSlice, "*".repeat(wordToSliceCharCount));
console.log(replacedChar);};

let email= "apple.pie@example.com";
console.log(maskEmail(email));

how do you establish what the output of your function is, or what your function is returning?

using return? maybe I need to use the literate thing or something?

what do you want to mention with “literate”?

anyway, yes, your function is missing the return

that’s the point I’m stuck at anyway I’m busy doing smth rn, so I might try tomorrow again

the first step would write the return keyword

also did you know you can make the editor format your code?

with right clicking and using “Format Document”

Or with the Shift+Alt+F keyboard shortcut

conventional formatting makes it easier for the people helping you to read your code

oh I didn’t know. :slight_smile: I’ll try to keep that in might. I’ll just had the return one rn or I’ll forget

I’ll still need help since I have no idea what I’m supposed to add.

function maskEmail(email) {
  let arobasePosition = email.indexOf("@");
  let wordToSlice = email.slice(1, arobasePosition);
 
  let wordToSliceCharCount = wordToSlice.length - 1;
  
  let replacedChar = email.replace(wordToSlice, "*".repeat(wordToSliceCharCount));


  return `"` + replacedChar + `"`;
};

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))

actually there’s some letter missing at the end of the emai before the arobase. I don’t know how to fix that.

first, you are not supposed to add quotes in the string

fixed that…

updated code under here

function maskEmail(email) {
  let arobasePosition = email.indexOf("@");
  let wordToSlice = email.slice(1, arobasePosition);

  let wordToSliceCharCount = wordToSlice.length - 1;

  let replacedChar = email.replace(wordToSlice, "*".repeat(wordToSliceCharCount));


  return replacedChar;
};

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))