--- id: 587d7fae367417b2b2512be5 title: Convert JSON Data to HTML challengeType: 6 forumTopicId: 16807 localeTitle: Преобразование данных JSON в HTML --- ## Description
Теперь, когда вы получаете данные из JSON API, вы можете отобразить его в HTML. Вы можете использовать метод forEach для циклического прохождения данных, поскольку объекты фотографии cat хранятся в массиве. По мере перехода к каждому элементу вы можете изменить элементы HTML. Сначала объявите html-переменную с var html = ""; , Затем прокрутите JSON, добавив HTML к переменной, которая обертывает имена ключей в strong тегах, а затем значение. Когда цикл закончен, вы его визуализируете. Вот код, который делает это:
json.forEach (function (val) {
var keys = Object.keys (val);
html + = "<div class = 'cat'>";
keys.forEach (функция (ключ) {
html + = "<strong>" + ключ + "</ strong>:" + val [key] + "<br>";
});
html + = "</ div> <br>";
});
## Instructions
Add a forEach method to loop over the JSON data and create the HTML elements to display it. Here is some example JSON ```json [ { "id":0, "imageLink":"https://s3.amazonaws.com/freecodecamp/funny-cat.jpg", "altText":"A white cat wearing a green helmet shaped melon on its head. ", "codeNames":[ "Juggernaut", "Mrs. Wallace", "Buttercup" ] } ] ```
## Tests
```yml tests: - text: Your code should store the data in the html variable testString: assert(code.match(/html\s+?(\+=|=\shtml\s\+)/g)); - text: Your code should use a forEach method to loop over the JSON data from the API. testString: assert(code.match(/json\.forEach/g)); - text: Your code should wrap the key names in strong tags. testString: assert(code.match(/.+<\/strong>/g)); ```
## Challenge Seed
```html

Cat Photo Finder

The message will go here

```
## Solution
```html // solution required ```