--- id: a6b0bb188d873cb2c8729495 title: Convert HTML Entities localeTitle: Convertir entidades HTML isRequired: true challengeType: 5 --- ## Description
Convierta los caracteres & , < , > , " (comillas dobles) y ' (apóstrofe), en una cadena a sus entidades HTML correspondientes. Recuerde usar Lectura-Búsqueda-Preguntar si se atasca. Intente vincular el programa. Escribe tu propio código.
## Instructions
## Tests
```yml tests: - text: ' convertHTML("Dolce & Gabbana") debe devolver Dolce &​amp; Gabbana . testString: 'assert.match(convertHTML("Dolce & Gabbana"), /Dolce & Gabbana/, "convertHTML("Dolce & Gabbana") should return Dolce &​amp; Gabbana.");' - text: ' convertHTML("Hamburgers < Pizza < Tacos") debe devolver Hamburgers &​lt; Pizza &​lt; Tacos . testString: 'assert.match(convertHTML("Hamburgers < Pizza < Tacos"), /Hamburgers < Pizza < Tacos/, "convertHTML("Hamburgers < Pizza < Tacos") should return Hamburgers &​lt; Pizza &​lt; Tacos.");' - text: ' convertHTML("Sixty > twelve") debe devolver Sixty &​gt; twelve . testString: 'assert.match(convertHTML("Sixty > twelve"), /Sixty > twelve/, "convertHTML("Sixty > twelve") should return Sixty &​gt; twelve.");' - text: ' convertHTML('Stuff in "quotation marks"') debería devolver Stuff in &​quot;quotation marks&​quot; . testString: 'assert.match(convertHTML("Stuff in "quotation marks""), /Stuff in "quotation marks"/, "convertHTML('Stuff in "quotation marks"') should return Stuff in &​quot;quotation marks&​quot;.");' - text: ' convertHTML("Schindler's List") debe devolver la Schindler&​apos;s List . testString: 'assert.match(convertHTML("Schindler"s List"), /Schindler's List/, "convertHTML("Schindler's List") should return Schindler&​apos;s List.");' - text: ' convertHTML("<>") debe devolver &​lt;&​gt; . testString: 'assert.match(convertHTML("<>"), /<>/, "convertHTML("<>") should return &​lt;&​gt;.");' - text: convertHTML("abc") debe devolver abc . testString: 'assert.strictEqual(convertHTML("abc"), "abc", "convertHTML("abc") should return 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]; }); } ```