Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

// fnc that is executed when data retrieved from the web.
function usersRetrieved(response) {
return response.json();
}

// next fnc handles when json data is ready
// you control what you want to do with data here. manipulate, console log, etc
function userJSONReady(users) {
const usersDiv = document.getElementById("users");
let usersHTML = "";
Expand All @@ -12,3 +15,35 @@ function userJSONReady(users) {
usersDiv.innerHTML = (usersHTML);
}

// decide what URL to use to call the data
// call the fetch fnc to start web request that returns a promise
// you decide what happens when web request is done.

fetch("https://jsonplaceholder.typicode.com/users")
.then (usersRetrieved)
.then(userJSONReady);


// fnc that is executed when data retrieved from the web.
function commentsRetrieved(response) {
return response.json();
}

// next fnc handles when json data is ready
// you control what you want to do with data here. manipulate, console log, etc
function commentJSONReady(comments) {
const commentsDiv = document.getElementById("comments");
let commentsHTML = "";
for (let i = 0; i < 10; i++) {
const comment = comments[i];
commentsHTML += "<div>" + comment.name + "</br>" + "</br>" + "</div>";
}
commentsDiv.innerHTML = (commentsHTML);
}


fetch("https://jsonplaceholder.typicode.com/comments")
.then (commentsRetrieved)
.then (commentJSONReady);