Build an Email Masker - Build an Email Masker

Tell us what’s happening:

This works so why is it not accepted. it has function named maskEmail , but it keeps acting as if it does not exist.

Your code so far

const email;
  
function maskEmail (email) {
    const [user, domain] = email.split('@');
    const userHidden = user[0] + "*".repeat(user.length - 2) + user.slice(-1)  
    return `${userHidden}@${domain}`;
    
}

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

Your browser information:

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

Challenge Information:

Build an Email Masker - Build an Email Masker

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-email-masker/66b205e6eacba4c4e54ea434.md at main · freeCodeCamp/freeCodeCamp · GitHub

hello!

please try to follow these User Story instructions properly –

  1. Outside the function, declare a variable named email to store the email address you want to mask.

  2. Call the maskEmail function with the email variable and output the result to the console.

i do not understand i can not make variabe set to one email because there are 4 of them.

so how do i declare 4 diff emails outside that equate to email. Is the solution

const email = user@domain; ?

or is it:

const email = user@example.com; ?

Please help i don’t know what i am doing.

Please review this theory lecture:

Introduction to JavaScript - What Are Variables, and What Are Guidelines for Naming JavaScript Variables? | Learn | freeCodeCamp.org

Here’s an excerpt from that:

One advantage of using the let keyword to declare variables is that you can reassign values to them.

Happy coding

ok i’ll do that as you suggested. wish me luck.

Tell us what’s happening:

I changed my variable to let so i could rename it as suggested,
Then I changed my function to use IndexOf instead of user /domain slit, but it is still not working what am I doing wrong? it is telling me iit is not a function. do i need to add a if sttement to make it a function?

Your code so far

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

function maskEmail(email) {
    const atIndex = email.indexOf('@');
    const userHidden = email.slice(0, atIndex);
    const domain = email.slice(atIndex);
    const emailHidden = userHidden[0] + "*".repeat(userHidden.length - 2) + userHidden.slice(-1);
   return `${emailHidden} + ${domain}`;
 
}

console.log(maskEmail(email));
let email = "freecodecamp@example.com"
console.log(maskEmail(email));
let email = "info@test.dev";
console.log(maskEmail(email));
let 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/148.0.0.0 Safari/537.36

Challenge Information:

Build an Email Masker - Build an Email Masker

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-email-masker/66b205e6eacba4c4e54ea434.md at main · freeCodeCamp/freeCodeCamp · GitHub

I went ahead and combined your posts for you. In the future, just reply to the original thread to add further updates. You can format your code as follows:


There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

Please review again the theory lecture about variables. This is important to understand.

Does a variable need to be declared over and over again?