--- id: a6b0bb188d873cb2c8729495 title: Convert HTML Entities isRequired: true challengeType: 5 --- ## Description
Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities. Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
## Instructions
## Tests
```yml tests: - text: convertHTML("Dolce & Gabbana") should return Dolce &amp; Gabbana. testString: assert.match(convertHTML("Dolce & Gabbana"), /Dolce & Gabbana/); - text: convertHTML("Hamburgers < Pizza < Tacos") should return Hamburgers &lt; Pizza &lt; Tacos. testString: assert.match(convertHTML("Hamburgers < Pizza < Tacos"), /Hamburgers < Pizza < Tacos/); - text: convertHTML("Sixty > twelve") should return Sixty &gt; twelve. testString: assert.match(convertHTML("Sixty > twelve"), /Sixty > twelve/); - text: convertHTML('Stuff in "quotation marks"') should return Stuff in &quot;quotation marks&quot;. testString: assert.match(convertHTML('Stuff in "quotation marks"'), /Stuff in "quotation marks"/); - text: convertHTML("Schindler's List") should return Schindler&apos;s List. testString: assert.match(convertHTML("Schindler's List"), /Schindler's List/); - text: convertHTML("<>") should return &lt;&gt;. testString: assert.match(convertHTML('<>'), /<>/); - text: convertHTML("abc") should return abc. testString: assert.strictEqual(convertHTML('abc'), 'abc'); ```
## Challenge Seed
```js function convertHTML(str) { // :) return str; } convertHTML("Dolce & Gabbana"); ```
## Solution
```js var MAP = { '&': '&', '<': '<', '>': '>', '"': '"', "'": '''}; function convertHTML(str) { return str.replace(/[&<>"']/g, function(c) { return MAP[c]; }); } ```