JSFiddle - React, Tailwind, and code Playground

by ananyaneogi

JavaScript

var output = document.getElementById('output');

var users = [];
var eachUser = [];

function getAllUsers() {
	fetch('https://api.github.com/users?since=1', {
		headers: new Headers({
		'Last-Modified': 'W/"baf56fe75095c17ae878b610f634d958"'
	})
})
  .then(
    function(response) {
      if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
      }

      // Examine the text in the response
      response.json().then(function(data) {
        data.map(user => {
        	users.push(user.login);
        })
        console.log(users);
      });
    }
  )
  .catch(function(err) {
    console.log('Fetch Error :-S', err);
  });
}
/*   getAllUsers()
   *//* users.map(user => getEachUser(user));
 */
  
  function getEachUser(login) {
    fetch('https://api.github.com/users/'+ login)
      .then(
        function(response) {
          if (response.status !== 200) {
            console.log('Looks like there was a problem. Status Code: ' +
              response.status);
            return;
          }

          // Examine the text in the response
          response.json().then(function(data) {
						var newUser = {
              	login: login,
                dateJoined: new Date(Date.parse(data.created_at.toString()))
              }
              eachUser.push(newUser);
            	console.log(eachUser);
          });
        }
      )
      .catch(function(err) {
        console.log('Fetch Error :-S', err);
      });
  }