Display images from an array

image, javascript

Solution

Change

width="160" height="120"

to

width='160' height='120'

In

document.write("<li><img src='" + backgroundImage[i] + "' width="160" height="120"/><span>" + backgroundImage[i] + "</span></li>");

You are using wrong quotation marks

Problem

I am trying to display six images from a javascript array. Running the code below I get no results it simply seems to be not working. I have no idea where my fault is. Here is the javascript code: ``` var backgroundImage = new Array(); backgroundImage[0] = "images/colors-wallpaper.jpg"; backgroundImage[1] = "images/florida-birds.jpg"; backgroundImage[2] = "images/focus-on-life.jpg"; backgroundImage[3] = "images/set-into-life.jpg"; backgroundImage[4] = "images/dandelion.jpg"; backgroundImage[5] = "images/flowers.jpg"; backgroundImage[5] = "images/flowers.jpg"; function displayAllImages() { // Here has to be some error!!! // for (i=0;i<backgroundImage.length;i++) { document.write("<li><img src='" + backgroundImage[i] + "' width="160" height="120"/><span>" + backgroundImage[i] + "</span></li>"); } } ``` And that's my html code: ``` <html> <head> <script type="text/javaScript" src="changebackground.js"></script> </head> <body> <div id="container"> <div class="backgoundImage"> <ul> <script>displayAllImages();</script> </ul> </div> </div> </body> </html> ```

Original source

Related problems