Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Hi. I feel like my logic is right but I think something is definitely missing. Please help.

Your code so far

let email = "domquau_45261@gmail.com";

function maskEmail(email){
  let newEmail = email.split();
  let len = newEmail.indexOf('@')
  for (let i = 1; i<len; i++){
      newEmail[i] = '*';
    }
  newEmail.join('');
  newEmail.toString();
  return newEmail;
}
console.log(maskEmail(email));

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

There are a couple of things to note here.
Firstly, you need to define a separator in your split method (even if it’s just an empty string) because otherwise you’ll just end up with:

['example@example.com']

Secondly, you’ll need to put the join method into your return statement as it doesn’t directly modify the array. Also, you don’t need the toString method at all here.

Finally, if you fix those things, your code will return the following:

maskEmail('example@example.com')
// returns 'e******@example.com'

…which doesn’t precisely match the requirements.