0

I want to load some images from a Javascript array but the images cannot be loaded. Can someone please have a look at my code?

Thank you

var works = [
  {
    title: "First Project",
    pic: "https://www.petfinder.com/wp-content/uploads/2012/09/Blog-Kitty-Cam-solo.jpg"
  },
  {
    title: "Second Project",
    pic: "http://www.animal-photography.com/thumbs/red_tabby_long_hair_kitten_~AP-0UJFTC-TH.jpg"
  },
  {
    title: "Third Project",
    pic: "http://www.animal-photography.com/thumbs/silver_tabby_kittens~AP-0JO6Y9-TH.jpg"
  },
  {
    title: "Fourth Project",
    pic: "http://www.animal-photography.com/thumbs/silver_tabby_kitten_looking_up~AP-0DLVMB-TH.jpg"
  }
];
      //works
   for(var i = 0; i < works.length; ++i) {
        //script for array goes here
        $('#work1').append('\
          <div class="col-xs-6 col-md-6 col-md-3">\
          <a href='#' class='work-img'>\
            <img class="img-responsive" src="' + works[i].pic + '">\
            <span class='info'><p class='proj-title'>Title:</p> src="' + works[i].title + '" </span>\
          </a>\
          </div>\
          ');//append closes

3
  • You can see what's wrong by the syntax highlighting. Your quotes make it a string Commented Mar 25, 2016 at 20:34
  • You have syntax errors in your concatenation. Console will tell you the story Commented Mar 25, 2016 at 20:34
  • Try opening your console (hit F12). Those error messages will help you a lot when you run into trouble. Commented Mar 25, 2016 at 20:36

1 Answer 1

1

I've corrected a few things in your code :

See this fiddle

JS code : //works

   for(var i = 0; i < works.length; ++i) {
        //script for array goes here

        $('#work1').append('<div class="col-xs-6 col-md-6 col-md-3">' +
         '<a href="#" class="work-img">' +
            '<img class="img-responsive" src="' + works[i].pic + '">' +
            '<span class="info"><p class="proj-title">Title:</p>' + works[i].title + '</span>' +
         '</a>' +
         '</div>'
          );//append closes
   }

The for loop wasn't closed and the concatenation of elements was wrong. Beside the title of each image wasn't print good as well.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you i got it to work. Thanks everyone for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.