I'm working with a JSON file in Javascript that I want to turn into single objects, where my next step is to have them in different cards in the HTML file.
API JSON file: http://jsonplaceholder.typicode.com/todos
I have fetched the API:
fetch("https://jsonplaceholder.typicode.com/todos")
.then(function (response) {
return response.json();
})
.then(function (json) {
consoleLogJson(json);
})
.catch(function (error) {
console.log(error);
});
Then I have looped through the results of the JSON:
function consoleLogJson(json) {
const resultsContainer = document.querySelector(".results");
const results = json;
for (let i = 0; i < results.length; i++) {
console.log("<div>Title: " + results[i].title + "</div>" + "<div>UserId: " + results[i].userId + "</div>" + "<div>Id: " + results[i].id + "</div>" + "<div>Completed: " + results[i].completed + "</div>");
}
}
This is my HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript - MA04 - Question 2</title>
<body>
<!-- Create a list of TODO cards using the API -->
<div class="results">
</div>
<script src="script.js"></script>
</body>
</html>
I am unsure what my next step should be.