mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat: add html entities lab to full stack curriculum (#61716)
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com> Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
This commit is contained in:
@@ -3397,6 +3397,12 @@
|
||||
"In this lab, you will design a sum all numbers algorithm. This algorithm takes an array of two numbers and returns the sum of those two numbers plus the sum of all the numbers between them."
|
||||
]
|
||||
},
|
||||
"lab-html-entitiy-converter": {
|
||||
"title": "Implement an HTML Entity Converter",
|
||||
"intro": [
|
||||
"In this lab, you will convert special characters in a string to their corresponding HTML entities."
|
||||
]
|
||||
},
|
||||
"review-javascript-fundamentals": {
|
||||
"title": "JavaScript Fundamentals Review",
|
||||
"intro": [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to Implement an HTML Entity Converter
|
||||
block: lab-html-entitiy-converter
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to Implement an HTML Entity Converter
|
||||
|
||||
In this lab, you will convert special characters in a string to their corresponding HTML entities.
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Implement an HTML Entity Converter",
|
||||
"isUpcomingChange": false,
|
||||
"dashedName": "lab-html-entitiy-converter",
|
||||
"superBlock": "full-stack-developer",
|
||||
"helpCategory": "JavaScript",
|
||||
"challengeOrder": [
|
||||
{
|
||||
"id": "a6b0bb188d873cb2c8729495",
|
||||
"title": "Implement an HTML Entity Converter"
|
||||
}
|
||||
],
|
||||
"usesMultifileEditor": true,
|
||||
"blockType": "lab",
|
||||
"blockLayout": "link"
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
---
|
||||
id: a6b0bb188d873cb2c8729495
|
||||
title: Implement an HTML Entity Converter
|
||||
challengeType: 26
|
||||
dashedName: implement-an-html-entity-converter
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
This lab is about converting special characters in a string with their corresponding HTML entities.
|
||||
|
||||
**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should have a `convertHTML` function that accepts a string as an argument.
|
||||
1. The `convertHTML` function should return a new string by converting special characters in the argument string to their corresponding HTML entities.
|
||||
|
||||
- `&` should be converted to `&`.
|
||||
- `<` should be converted to `<`.
|
||||
- `>` should be converted to `>`.
|
||||
- `"` should be converted to `"`.
|
||||
- `'` should be converted to `'`.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `convertHTML` function.
|
||||
|
||||
```js
|
||||
assert.isFunction(convertHTML);
|
||||
```
|
||||
|
||||
`convertHTML("Dolce & Gabbana")` should return the string `Dolce & Gabbana`.
|
||||
|
||||
```js
|
||||
assert.match(convertHTML('Dolce & Gabbana'), /Dolce & Gabbana/);
|
||||
```
|
||||
|
||||
`convertHTML("Hamburgers < Pizza < Tacos")` should return the string `Hamburgers < Pizza < Tacos`.
|
||||
|
||||
```js
|
||||
assert.match(
|
||||
convertHTML('Hamburgers < Pizza < Tacos'),
|
||||
/Hamburgers < Pizza < Tacos/
|
||||
);
|
||||
```
|
||||
|
||||
`convertHTML("Sixty > twelve")` should return the string `Sixty > twelve`.
|
||||
|
||||
```js
|
||||
assert.match(convertHTML('Sixty > twelve'), /Sixty > twelve/);
|
||||
```
|
||||
|
||||
`convertHTML('Stuff in "quotation marks"')` should return the string `Stuff in "quotation marks"`.
|
||||
|
||||
```js
|
||||
assert.match(
|
||||
convertHTML('Stuff in "quotation marks"'),
|
||||
/Stuff in "quotation marks"/
|
||||
);
|
||||
```
|
||||
|
||||
`convertHTML("Schindler's List")` should return the string `Schindler's List`.
|
||||
|
||||
```js
|
||||
assert.match(convertHTML("Schindler's List"), /Schindler's List/);
|
||||
```
|
||||
|
||||
`convertHTML("<>")` should return the string `<>`.
|
||||
|
||||
```js
|
||||
assert.match(convertHTML('<>'), /<>/);
|
||||
```
|
||||
|
||||
`convertHTML("abc")` should return the string `abc`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(convertHTML('abc'), 'abc');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
const map = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
};
|
||||
|
||||
function convertHTML(str) {
|
||||
return str.replace(/[&<>"']/g, function(char) {
|
||||
return map[char];
|
||||
});
|
||||
}
|
||||
```
|
||||
@@ -788,6 +788,9 @@
|
||||
{
|
||||
"dashedName": "lab-sum-all-numbers-algorithm"
|
||||
},
|
||||
{
|
||||
"dashedName": "lab-html-entitiy-converter"
|
||||
},
|
||||
{
|
||||
"dashedName": "review-javascript-fundamentals"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user