Build an Email Masker - Build an Email Masker

Tell us what’s happening:

This is the hardest lab yet. Not passing numbers 5, 6, 7. I have researched w3 schools and the forum. Every other code is way different than mine, and I cant figure out why. Any advice is greatly appreciated.

Your code so far

function maskEmail(email){
  let slicer = email.slice(1,indexer);
  let indexer = (email.indexOf('@')-1);
  let hide = '*';
  let replaced = email.replace(slicer,hide.repeat(indexer));
  return(replaced);
}

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

email = 'freecodecamp@example.com';
maskEmail(email);
console.log(maskEmail(email));

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/18.5 Safari/605.1.15

Challenge Information:

Build an Email Masker - Build an Email Masker

first, return is not a function, but it still work so that is not an issue.

It doesn’t matter if your code is a lot different than what other people use, it can be.

The issue is that your code does not return the correct output:
apple.pie@example.com becomes a******** when it should become a*******e@example.com


what do you think is the value of indexer on the first line?

Indexer would be the part of the email address up to the @ symbol correct?

you use indexer on the first of these two lines, so what’s the value of indexer there?

  let slicer = email.slice(1,indexer);
  let indexer = (email.indexOf('@')-1);

it’s important you know what the value of indexer is on the first of these two lines. You can add a console.log for verification

let slicer = email.slice(1,8,indexer);

this correctly shows a*******e@example.com, but the freecodecamp@example.com is not displaying correctly. How do I set the code different for each one? or is there something I can use to work for both of them?

that’s not what I am asking, please focus on what I am asking

if you add

  console.log(indexer)
  let slicer = email.slice(1,indexer);
  let indexer = (email.indexOf('@')-1);

what value does it show for indexer?

it’s really important for solving your issues

It is showing

undefined
undefined
a******* p@example.com
undefined
undefined
f*******camp@example .com

so it is showing that the value of indexer there is undefined, do you know why?

Haven’t the slightest idea, I guess I am confused as there was nothing in the lecture about this problem.

where is indexer defined?

With in the Function, should I move it above the 2nd line and make it the first line, so the referenced indexer in line three can reference it?

try that, yes  

still getting undefined X2 as mentioned before

show me the code please

function maskEmail(email){
  let indexer = (email.indexOf('@')+1);
  let slicer = email.slice(1,8,indexer);
  let hide = '*';
  let replaced = email.replace(slicer,hide.repeat(indexer));
  return(replaced);
}

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

email = 'freecodecamp@example.com';
maskEmail(email);
console.log(maskEmail(email));

and where is the undefined from? there is no console.log there printing indexer

So its showing:
10
10
a**********e@example.com
13
13

function maskEmail(email){
  let indexer = (email.indexOf('@')+1);
  console.log(indexer);
  let slicer = email.slice(1,8,indexer);
  let hide = '*';
  let replaced = email.replace(slicer,hide.repeat(indexer));
  return(replaced);
}

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

email = 'freecodecamp@example.com';
maskEmail(email);
console.log(maskEmail(email));

no undefined now, right?

Ok, now you changed the slicer definition for some reason earlier. Remember that slice takes only two arguments, so the third one has no effect

So when I added in the 8 for the slicer it showed the ‘e’ in pie for the email address

Its been removed now

function maskEmail(email){
  let indexer = (email.indexOf('@')+1);
  console.log(indexer);
  let slicer = email.slice(1,indexer);
  let hide = '*';
  let replaced = email.replace(slicer,hide.repeat(indexer));
  return(replaced);
}

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

email = 'freecodecamp@example.com';
maskEmail(email);
console.log(maskEmail(email));