Tell us what’s happening:
I tried four ways already in codepen.io already! three ways worked properly. Can you all please help me? What have I done wrong with this code . 3. Outside the function, you should have an email variable.
4. You should assign a valid email address to your email variable.
8. You should log the output of calling maskEmail with email as argument.
// tests completed
// console output
ae@example.com
f***p@example.com
Your code so far
function maskEmail(email){
const indexOf = email.indexOf('@');
const localPart = email.slice (0, indexOf);
const domainPart = email.slice(indexOf);
let maskedLocalPart = localPart[0] + "*".repeat(localPart.length-2) + localPart[localPart.length-1];
return maskedLocalPart + domainPart;
}
let email1 = maskEmail("apple.pie@example.com");
let email2 = maskEmail("freecodeCamp@example.com");
console.log(maskEmail(email1));
console.log(maskEmail(email2));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Challenge Information:
Build an Email Masker - Build an Email Masker