Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Hi, I stuck at a point. I tried to write it twice with different way but I don’t understand what’s the problem, can you help me please?

let email = (“apple.pie@example.com”);
function maskEmail(email) {
let findName = email.slice(1, (email.indexOf(“@”) -1))
let hideName = (“*”.repeat(findName.length))
let fullName = (
email.slice(0, 1) +
hideName +
email.slice((email.indexOf(“@”)-1), email.indexOf(“@”)) +
email.slice(email.indexOf(“@”), (email.length))
);
}

maskEmail(email);

Your code so far

let email = ("apple.pie@example.com");
function maskEmail(email) {
let findName = email.slice(1, (email.indexOf("@") -1))
let hideName = ("*".repeat(findName.length))
let fullName = (
  email.slice(0, 1) + 
  hideName + 
  email.slice((email.indexOf("@")-1), email.indexOf("@")) + 
  email.slice(email.indexOf("@"), (email.length))
);
}

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

Challenge Information:

Build an Email Masker - Build an Email Masker

What does your output look like?

Normally it’s doing exactly what it asks, but when I run it it says;

“// running tests
5. maskEmail(“apple.pie@example.com”) should return “a*******e@example.com”.
6. maskEmail(“freecodecamp@ example .com”) should return “f**********p@example.com”.
7. maskEmail(“info@test.dev”) should return “i**o@test.dev”.
8. maskEmail(“user@domain.org”) should return “u**r@domain.org”.
9. Your maskEmail should produce the correct result.
10. You should log the output of calling maskEmail with email as argument.
// tests completed"

Normally it’s doing exactly what it asks, but when I run it it says;

“maskEmail(“apple.pie @example.com”) should return “a*******e@example.com”.” and repeating for every option.

How can you tell?

When you try an example email what does the output look like?

What output does your function give for "apple.pie@example.com" ?

I tried it outside of function, and log the fullName value, and it’s doing for example “a*******e@example.com”,
I moved the whole code inside of the function, and it’s not working

Aaah, I did it. The problem was return. There is no return at my code. I write return fullName and it worked!

I’m sorry. I’m still trying to learn. Thanks for helping :folded_hands:

1 Like

You solved it, no need to apologize. That’s all part of learning.

Evaluating the actual output of your function is crucial for debugging.

1 Like