Build an Email Masker - Build an Email Masker

Tell us what’s happening:

Passing all tests except “10. You should log the output of calling maskEmail with email as argument.” I have the statement console.log(maskEmail(email)); in my code and see the expected output logged to the console. What about this breaks the test condition #10?

Your code so far

function maskEmail(email){
  let atIndex = email.indexOf("@")
  let head=email.slice(0,1);
  let tail=email.slice(atIndex-1);
  let masked = "*".repeat(atIndex-2);
  return head+masked+tail;
}
let email="apple.pie@example.com"
console.log (maskEmail(email));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build an Email Masker - Build an Email Masker

Your spacing is a little unusual. console.log is a function, so I would keep your spacing consistent with calling a function.

https://www.w3schools.com/js/js_conventions.asp

Should also have whitespace around the =

https://www.w3schools.com/js/js_conventions.asp

https://standardjs.com/rules.html

Here you have spaces around =

Here you have no space between the function name and the parentheses

but here there’s space

Thanks!

console.log(maskEmail(email));

works.

I’ve been paying no attention to whitespace. Is it fair to say that whitespace is insignificant in JavaScript (automatic semicolon insertion notwithstanding) but freeCodeCamp enforces some style conventions?

Yes and no.

At the very least it makes your code look messy and amateurish. It’s slightly harder to read for other people, which is important when you share your code and asking for help from other people who have to read it.

freeCodeCamp does run JS in something called strict mode which does have more strict syntax requirements than other environments. However, you didn’t get a syntax error so I don’t think this was related to that. It might have interfered with the test on the back end though, I would have to investigate that further…

I would encourage you to type well formatted code, however you can also right-click in the editor and select “format document”. Most programmers would have an auto-formatter installed that formats their code every time they save.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.