Build an Email Masker

let email = "chikadibia@gmail.com";

function maskEmail(email){
  if(email.indexOf("@") !== -1){

    let slicedOffEmail = email.slice(1, email.indexOf("@") - 1);

    let slicedOffEmailLength = slicedOffEmail.length;

    let asteriks = "*".repeat(slicedOffEmailLength);

   email =  email.replace(slicedOffEmail, asteriks);

  }else{
    email =  "Email Address Is Incorrect";
  }
  return email;
}
console.log(maskEmail(email))

Build an Email Masker: Build an Email Masker | freeCodeCamp.org

Welcome to the forum @ChikaDibia,

Do you have a question about the code you posted?

I’ve edited your post to add a link to the challenge. In the future when you need help, please use the “Help” button on the challenge.

Happy coding

Yes, please.
I have run the code, but it doesn’t pass some test cases.
I can’t find the problem.
Can you please check if I did anything wrong?

@dhess
Yes, please.
I have run the code, but it doesn’t pass some test cases.
I can’t find the problem.
Can you please check if I did anything wrong?

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

@dhess
Thanks so much :folded_hands:

I tried the first solution, and it worked.