DEV Community

Discussion on: Fetch Exercise (Github users)

savagepixie profile image

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); = `${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 =;

  var avatar = document.createElement('img');
  var src = document.querySelector(`#${responseJson.login}_1`);
  avatar.src = responseJson.avatar_url;
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 .

savagepixie profile image

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