--- id: 587d7fae367417b2b2512be5 title: Convert JSON Data to HTML challengeType: 6 videoUrl: '' localeTitle: Convertir datos JSON a HTML --- ## Description
Ahora que está obteniendo datos de una API JSON, puede mostrarlos en el HTML. Puede usar un método forEach para recorrer los datos, ya que los objetos de la foto del gato se mantienen en una matriz. A medida que llegas a cada elemento, puedes modificar los elementos HTML. Primero, declare una variable html con var html = ""; . Luego, recorra el JSON, agregando HTML a la variable que envuelve los nombres de las claves en etiquetas strong , seguido del valor. Cuando el bucle termina, lo renderizas. Aquí está el código que hace esto:
json.forEach (función (val) {
var keys = Object.keys (val);
html + = "<div class = 'cat'>";
keys.forEach (function (key) {
html + = "<strong>" + clave + "</strong>:" + val [clave] + "<br>";
});
html + = "</div> <br>";
});
## Instructions
Agregue un método forEach para recorrer los datos JSON y crear los elementos HTML para mostrarlos. Aquí hay un ejemplo de JSON
El
{
"id": 0,
"imageLink": "https://s3.amazonaws.com/freecodecamp/funny-cat.jpg",
"altText": "Un gato blanco con un casco verde con forma de melón en la cabeza".
"codeNames": ["Juggernaut", "Mrs. Wallace", "Buttercup"
]
}
]
## Tests
```yml tests: - text: Su código debe almacenar los datos en la variable html testString: 'assert(code.match(/html\s+?(\+=|=\shtml\s\+)/g), "Your code should store the data in the html variable");' - text: Su código debe utilizar un método forEach para recorrer en bucle los datos JSON de la API. testString: 'assert(code.match(/json\.forEach/g), "Your code should use a forEach method to loop over the JSON data from the API.");' - text: Su código debe envolver los nombres de las claves en etiquetas strong . testString: 'assert(code.match(/.+<\/strong>/g), "Your code should wrap the key names in strong tags.");' ```
## Challenge Seed
```html

Cat Photo Finder

The message will go here

```
## Solution
```js // solution required ```