DEV Community

Discussion on: Fetch Exercise (Github users)

Collapse
savagepixie profile image
SavagePixie

The problem is that you're always selecting the same cells to update the innerHTML. There is only one cell in your table with the class username__cell and so on. What you need to do in step 2 is dynamically generate something to identify the cells that you create. A unique ID would work. You could try something like this:

for (var c = 0; c < 3; c++) {

    var cell = row.insertCell(c);
        cell.id = `${responseJson.login}_${c}`
  };

  //How to populate one line
  document.querySelector(`#${responseJson.login}_0`).innerHTML = responseJson.login;
  document.querySelector(`#${responseJson.login}_1`).innerHTML = responseJson.avatar_url;
  document.querySelector(`#${responseJson.login}_2`).innerHTML = responseJson.bio;

  var avatar = document.createElement('img');
  var src = document.querySelector(`#${responseJson.login}_1`);
  avatar.src = responseJson.avatar_url;
  src.appendChild(avatar);
Collapse
manuelalonge profile image
Manuel Alonge Author

It works. Now I should only refactor it in order to do it dinamically (i.e. if I had more than only two users). Thanks @savagepixie .

Collapse
savagepixie profile image
SavagePixie

You're welcome^ I'm glad I could help