feat(curriculum): add email masker lab (#55768)

Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
This commit is contained in:
Zaira
2024-09-03 20:38:35 +05:00
committed by GitHub
parent 0f69c1d8ac
commit 9ce026926d
4 changed files with 128 additions and 2 deletions
+6 -2
View File
@@ -1917,7 +1917,6 @@
},
"axgb": { "title": "138", "intro": [] },
"rwac": { "title": "139", "intro": [] },
"uzjg": { "title": "140", "intro": [] },
"hxwa": { "title": "141", "intro": [] },
"xkbo": { "title": "142", "intro": [] },
"nkxq": { "title": "143", "intro": [] },
@@ -1935,7 +1934,12 @@
"In this workshop, you will review working with functions by building a calculator."
]
},
"hqba": { "title": "153", "intro": [] },
"lab-email-masker": {
"title": "Build an Email Masker",
"intro": [
"In this lab, you'll build an email masker that will take an email address and obscure it."
]
},
"lab-sentence-maker": {
"title": "Build a Sentence Maker",
"intro": [
@@ -0,0 +1,9 @@
---
title: Introduction to the Build an Email Masker
block: lab-email-masker
superBlock: front-end-development
---
## Introduction to the Build an Email Masker
In this lab, you'll build an email masker that will take an email address and obscure it.
@@ -0,0 +1,11 @@
{
"name": "Build an Email Masker",
"isUpcomingChange": true,
"usesMultifileEditor": true,
"dashedName": "lab-email-masker",
"order": 153,
"superBlock": "front-end-development",
"challengeOrder": [{ "id": "66b205e6eacba4c4e54ea434", "title": "Build an Email Masker" }],
"helpCategory": "JavaScript",
"blockType": "lab"
}
@@ -0,0 +1,102 @@
---
id: 66b205e6eacba4c4e54ea434
title: Build an Email Masker
challengeType: 14
dashedName: build-an-email-masker
---
# --description--
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.
For example, if the email address was `myEmail@email.com`, then the masked email address will be `m*******l@email.com`.
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. Create a function named `maskEmail` that takes `email` as an argument.
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.
3. Outside the function, declare a variable named `email` to store the email address you want to mask.
4. Call the `maskEmail` function with the `email` variable and output the result to the console.
5. `maskEmail("apple.pie@example.com")` should return `"a*******e@example.com"`.
6. `maskEmail("freecodecamp@example.com")` should return `"f**********p@example.com"`.
# --hints--
You should define a funtion named `maskEmail`.
```js
assert.isFunction(maskEmail);
```
The `maskEmail` funtion should take a string, `email` as an argument.
```js
assert.match(maskEmail.toString(), /\s*maskEmail\(\s*\w+\s*\)/);
```
Outside the function, you should have an `email` variable.
```js
assert.isDefined(email);
```
You should assign a valid email address to your `email` variable.
```js
assert.match(email, /^[\w\.-]+@[a-zA-Z\d\.-]+\.[a-zA-Z]{2,}$/);
```
`maskEmail("apple.pie@example.com")` should return `"a*******e@example.com"`.
```js
assert.strictEqual(maskEmail("apple.pie@example.com"),"a*******e@example.com");
```
`maskEmail("freecodecamp@example.com")` should return `"f**********p@example.com"`.
```js
assert.strictEqual(maskEmail("freecodecamp@example.com"), "f**********p@example.com");
```
Your `maskEmail` should produce the correct result.
```js
assert.strictEqual(maskEmail("johnappleseed@email.com"), "j***********d@email.com");
assert.strictEqual(maskEmail("john.doe@example.com"), "j******e@example.com");
assert.strictEqual(maskEmail("jane.smith@sample.org"), "j********h@sample.org");
assert.strictEqual(maskEmail("michael.jordan@testmail.net"), "m************n@testmail.net");
```
You should log the function call to `maskEmail` to the console.
```js
assert.match(__helpers.removeJSComments(code), /console\.log\(maskEmail\(email\)\)/);
```
# --seed--
## --seed-contents--
```js
```
# --solutions--
```js
function maskEmail(email) {
const atIndex = email.indexOf("@");
const userName = email.slice(0, atIndex);
const domain = email.slice(atIndex);
const maskedName =
userName[0] + "*".repeat(userName.length - 2) + userName[userName.length - 1] + domain;
return maskedName;
}
const email = "apple.pie@example.com";
console.log(maskEmail(email));
```