Build an Email Masker - Build an Email Masker

Tell us what’s happening:

My output prints the desired results. But for some reason there is something wrong with my code, as if I’m missing something. NOTE: I used the commented code, and it did not pass still.

Your code so far

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

const maskEmail = (email) => {

const atIndex = email.indexOf("@") -1
const firstChar = email[0]
const domain = email.slice(atIndex)
const maskLength = atIndex 
const stars = "*".repeat(maskLength);
return firstChar + stars + domain;
}
console.log(maskEmail(email))

console.log(maskEmail("freecodecamp@example.com"))
console.log(maskEmail("info@test.dev"))
console.log(maskEmail("user@domain.org"))
console.log(maskEmail("user@domain.org"))

// email = "freecodecamp@example.com" 
// console.log(maskEmail(email))
// email = "info@test.dev"
// console.log(maskEmail(email))
// email = "user@domain.org"
// console.log(maskEmail(email))
// email = "user@domain.org"
// console.log(maskEmail(email))

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

Welcome to the forum @morgansamuel960 !

Have you tried logging your variables inside the function to see if they are what you expect?

Happy coding!

Yes, I checked what the output for every variable in the function is. And they all output what I expect.

And do you see now where your issue is? Just test for one email, say, “apple.pie@example.com”. What does your code return? What should it return?

OH, I see. The problem was in the function code block