Here, you hard-coded informations in your code. Learn here more about hard-coding. You have to think that it has to work not only for this specific email, but for all emails.
Hmm, I see. If hardcoding does not work, how do I combine the replace() and slice() methods using the first and last indexes to mask any email?
For example, the code I always think of is
const maskedEmail = slicedEmail.replace(slicedEmail.slice(1, -1), “*”), but I don’t understand how to use the repeat() for the asterisks without hardcoding.
You’re on the good path, but you need to review a few points in your code.
Here, slicedEmail is hardcoded. It will always take from the 0 index character to the 6 index character , no matter the email’s length. Hint : Think about the fact that all email adresses have a “@” character. You could use the indexOf()function too.
Your idea was really good ! const maskedEmail = slicedEmail.replace(slicedEmail.slice(1, -1), “*”) is an excellent beginning. Now all you need to do is to is to implement the replace() syntax. Use the lesson to help you. If you can’t understand it, we will help you further on that. Hint :Think about the length property of your string.
After analyzing your suggestions above, I was able to figure out the issue! First, I needed to define the replacementCharacter outside of my function in order to use the repeat() method for the asterisks. Secondly, I had to define the slicedEmailLength to determine the asterisk replacement amount. Thirdly, I needed to use the indexOf() method for the @ symbol in the domain operation.
Essentially, I had to do a lot of defining in order to use the methods.
Well, if you got it, congrats ! It was a tough step, but you managed trough it ! Don’t give up, and I wish you the best of luck during your learning ! Enjoy coding