Build an Email Masker - Build an Email Masker

Tell us what’s happening:

I have finished my code and getting the desired result, masking the characters in between the first and last letters of the username. However, my code wnt go through and stuck at number 5.

Your code so far

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

function maskEmail(email) {

        const splitEmail = email.toLowerCase().split("@");
        
        const splitUsername = splitEmail[0].split("");
        
        const charToBeReplaced = splitUsername.slice(1, -1);
        
        const asterisk = "*";
               
        const numOfAsterisk = asterisk.repeat(charToBeReplaced.length);
        
        const newEmail = `"${splitUsername[0]}${numOfAsterisk}${splitUsername[splitUsername.length - 1]}@${splitEmail[1]}"`;    

        return newEmail;
}

maskEmail(email);

console.log(maskEmail("apple.pie@example.com"));
console.log(maskEmail("freecodecamp@example.com"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

The failed test is

  1. maskEmail("apple.pie@example.com") should return "a*******e@example.com" .

So let’s check what it returns:

console.log("actual  ", maskEmail("apple.pie@example.com"));
console.log("expected", "a*******e@example.com")

this prints

actual   "a*******e@example.com"
expected a*******e@example.com

it looks like you have extra quote characters

1 Like

Oooh! :blush:

Thanks much!