Skip to content
Open
Show file tree
Hide file tree
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
32 changes: 31 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@

// function that is executed when the fetch call is done retrieving the data
// the function will always be the same
// one argument, one response - return response.json()
function usersRetrieved(response) {
return response.json();
}

// this function handles the data once the json object is ready
function userJSONReady(users) {
const usersDiv = document.getElementById("users");
let usersHTML = "";
Expand All @@ -12,3 +16,29 @@ function userJSONReady(users) {
usersDiv.innerHTML = (usersHTML);
}

// fetch call to URL then passing in the usersRetrieved and userJSONReady functions
const fetchCall = fetch("https://jsonplaceholder.typicode.com/users");
const getJsonPromise = fetchCall.then(usersRetrieved);
getJsonPromise.then(userJSONReady);


// function for when comments fetch call is complete
function commentsRetrieved(response){
return response.json();
}

// function to handle data when the fetch call is complete
function commentsJSONReady(comments){
const commentsDiv = document.getElementById("comments");
let commentsHTML = "";
for (let i = 0; i < comments.length; i++){
const comment = comments[i];
commentsHTML += "<div>" + comment.name + "</div>" ;
}
commentsDiv.innerHTML = (commentsHTML);
}

// fetch call to comments and format data for webpage
const commentsCall = fetch("https://jsonplaceholder.typicode.com/comments");
const commentsJsonPromise = commentsCall.then(commentsRetrieved);
commentsJsonPromise.then(commentsJSONReady);
21 changes: 2 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,6 @@ binary-extensions@^1.0.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.8.0.tgz#48ec8d16df4377eae5fa5884682480af4d95c774"

biskviit@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/biskviit/-/biskviit-1.0.1.tgz#037a0cd4b71b9e331fd90a1122de17dc49e420a7"
dependencies:
psl "^1.1.7"

block-stream@*:
version "0.0.9"
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
Expand Down Expand Up @@ -2090,7 +2084,7 @@ encodeurl@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"

encoding@0.1.12, encoding@^0.1.11:
encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
Expand Down Expand Up @@ -2567,13 +2561,6 @@ fbjs@^0.8.9:
setimmediate "^1.0.5"
ua-parser-js "^0.7.9"

fetch@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fetch/-/fetch-1.1.0.tgz#0a8279f06be37f9f0ebb567560a30a480da59a2e"
dependencies:
biskviit "1.0.1"
encoding "0.1.12"

figures@^1.3.5:
version "1.7.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-1.7.0.tgz#cbe1e3affcf1cd44b80cadfed28dc793a9701d2e"
Expand Down Expand Up @@ -4876,7 +4863,7 @@ promise@7.1.1, promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.7, prop-types@^15.5.8, prop-types@~15.5.7:
prop-types@^15.5.7, prop-types@~15.5.7:
version "15.5.8"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.8.tgz#6b7b2e141083be38c8595aa51fc55775c7199394"
dependencies:
Expand All @@ -4897,10 +4884,6 @@ pseudomap@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"

psl@^1.1.7:
version "1.1.18"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.18.tgz#a8f2f5465a01e8acce4ff2d72342b05c7b507d90"

punycode@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
Expand Down