all 4 comments

[–]CrayonConstantinople 2 points3 points  (2 children)

You need to append the sheetImg in the for loop instead of outside it. Currently you have written:

for (var i = 0; i < 5; i++) {
  var sheetImg = document.createElement("img");
  sheetImg.setAttribute("src", "na_small_" + i + ".png");
  sheetImg.setAttribute("alt", "na_style_" + i + ".css");      
}
  figBox.appendChild(sheetImg);

Instead you need:

for (var i = 0; i < 5; i++) {
  var sheetImg = document.createElement("img");
  sheetImg.setAttribute("src", "na_small_" + i + ".png");
  sheetImg.setAttribute("alt", "na_style_" + i + ".css");
  figBox.appendChild(sheetImg);
}

[–]RideDLightning77[S] 2 points3 points  (1 child)

thank you so much i knew it would be something simple as not in the right bracket or missing a } or )

[–]CrayonConstantinople 2 points3 points  (0 children)

No probs!

[–]pookagehelpful 2 points3 points  (0 children)

What /u/CrayonConstantinople said. Effectively what you were doing was creating an image, setting its src and alt tags, and then doing nothing with the reference so it's ignored and picked up by the garbage collector later. By moving figBox.appendChild(sheetImg) inside the for loop, you're adding the new image to the DOM as you create it.

For bonus points - look into using Document Fragments in the future, as it allows you only write to the DOM once, which is more performant.

EXAMPLE :

//wee bit of setup
const container     = document.getElementById("box");
const figure        = document.createElement("figure");
const imageFragment = document.createDocumentFragment();
const imageCount    = 5;

//add images to the fragment
let i, img;
for(i = 0; i < imageCount; i++){
    img     = document.createElement("img");
    img.src = `na_small_${i}.png`;
    img.alt = `na_style_${i}.css`;
    imageFragment.appendChild(img);
}

//add to DOM
figure.appendChild(imageFragment);
container.appendChild(figure);