Skip to content

Commit 9ce0269

Browse files
zairahirajdwilkin4
andauthored
feat(curriculum): add email masker lab (freeCodeCamp#55768)
Co-authored-by: Jessica Wilkins <[email protected]>
1 parent 0f69c1d commit 9ce0269

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,6 @@
19171917
},
19181918
"axgb": { "title": "138", "intro": [] },
19191919
"rwac": { "title": "139", "intro": [] },
1920-
"uzjg": { "title": "140", "intro": [] },
19211920
"hxwa": { "title": "141", "intro": [] },
19221921
"xkbo": { "title": "142", "intro": [] },
19231922
"nkxq": { "title": "143", "intro": [] },
@@ -1935,7 +1934,12 @@
19351934
"In this workshop, you will review working with functions by building a calculator."
19361935
]
19371936
},
1938-
"hqba": { "title": "153", "intro": [] },
1937+
"lab-email-masker": {
1938+
"title": "Build an Email Masker",
1939+
"intro": [
1940+
"In this lab, you'll build an email masker that will take an email address and obscure it."
1941+
]
1942+
},
19391943
"lab-sentence-maker": {
19401944
"title": "Build a Sentence Maker",
19411945
"intro": [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Introduction to the Build an Email Masker
3+
block: lab-email-masker
4+
superBlock: front-end-development
5+
---
6+
7+
## Introduction to the Build an Email Masker
8+
9+
In this lab, you'll build an email masker that will take an email address and obscure it.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Build an Email Masker",
3+
"isUpcomingChange": true,
4+
"usesMultifileEditor": true,
5+
"dashedName": "lab-email-masker",
6+
"order": 153,
7+
"superBlock": "front-end-development",
8+
"challengeOrder": [{ "id": "66b205e6eacba4c4e54ea434", "title": "Build an Email Masker" }],
9+
"helpCategory": "JavaScript",
10+
"blockType": "lab"
11+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
id: 66b205e6eacba4c4e54ea434
3+
title: Build an Email Masker
4+
challengeType: 14
5+
dashedName: build-an-email-masker
6+
---
7+
8+
# --description--
9+
10+
In this lab, you will mask the username part of an email address with asterisks. Masking is a term used to hide or replace sensitive information with asterisks or other characters.
11+
12+
For example, if the email address was `[email protected]`, then the masked email address will be `m*******[email protected]`.
13+
14+
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
15+
16+
**User Stories:**
17+
18+
1. Create a function named `maskEmail` that takes `email` as an argument.
19+
2. Inside the function, you should mask the `email` and append the domain name to it. Remember that you can use methods like `slice`, `repeat`, `indexOf` `slice` or even `replace` to help you.
20+
3. Outside the function, declare a variable named `email` to store the email address you want to mask.
21+
4. Call the `maskEmail` function with the `email` variable and output the result to the console.
22+
5. `maskEmail("[email protected]")` should return `"a*******[email protected]"`.
23+
6. `maskEmail("[email protected]")` should return `"f**********[email protected]"`.
24+
25+
# --hints--
26+
27+
You should define a funtion named `maskEmail`.
28+
29+
```js
30+
assert.isFunction(maskEmail);
31+
```
32+
33+
The `maskEmail` funtion should take a string, `email` as an argument.
34+
35+
```js
36+
assert.match(maskEmail.toString(), /\s*maskEmail\(\s*\w+\s*\)/);
37+
```
38+
39+
Outside the function, you should have an `email` variable.
40+
41+
```js
42+
assert.isDefined(email);
43+
```
44+
45+
You should assign a valid email address to your `email` variable.
46+
47+
```js
48+
assert.match(email, /^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$/);
49+
```
50+
51+
`maskEmail("[email protected]")` should return `"a*******[email protected]"`.
52+
53+
```js
54+
assert.strictEqual(maskEmail("[email protected]"),"a*******[email protected]");
55+
```
56+
57+
`maskEmail("[email protected]")` should return `"f**********[email protected]"`.
58+
59+
```js
60+
assert.strictEqual(maskEmail("[email protected]"), "f**********[email protected]");
61+
```
62+
63+
Your `maskEmail` should produce the correct result.
64+
65+
```js
66+
assert.strictEqual(maskEmail("[email protected]"), "j***********[email protected]");
67+
assert.strictEqual(maskEmail("[email protected]"), "j******[email protected]");
68+
assert.strictEqual(maskEmail("[email protected]"), "j********[email protected]");
69+
assert.strictEqual(maskEmail("[email protected]"), "m************[email protected]");
70+
```
71+
72+
You should log the function call to `maskEmail` to the console.
73+
74+
```js
75+
assert.match(__helpers.removeJSComments(code), /console\.log\(maskEmail\(email\)\)/);
76+
```
77+
78+
# --seed--
79+
80+
## --seed-contents--
81+
82+
```js
83+
84+
```
85+
86+
# --solutions--
87+
88+
```js
89+
function maskEmail(email) {
90+
const atIndex = email.indexOf("@");
91+
const userName = email.slice(0, atIndex);
92+
const domain = email.slice(atIndex);
93+
94+
const maskedName =
95+
userName[0] + "*".repeat(userName.length - 2) + userName[userName.length - 1] + domain;
96+
97+
return maskedName;
98+
}
99+
100+
const email = "[email protected]";
101+
console.log(maskEmail(email));
102+
```

0 commit comments

Comments
 (0)