Click here to Skip to main content
14,699,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am unable to make this webpage to display anything. When I try to open it there are no pictures that display. This code is straight from the book other, than the pictures I used.

<title>HTML and JavaScript

var imgArray = new Array(6);
var index = 0;

function cycle()
	{
	  document.banner.src - imgArray[index].src;
	  index++;
	  if (index > 6)
	  {
	    index = 0;
	  }
	  setTimeout("cycle()", 2000);
	  return;
	}
function startup()
	{
	  imgArray[0] = new Image;
	  imgArray[0].src = "Linx.png";
	  imgArray[1] = new Image;
	  imgArray[1].src = "Fish.png";
	  imgArray[2] = new Image;
	  imgArray[2].src = "Crocodile.png";
	  imgArray[3] = new Image;
	  imgArray[3].src = "Gorilla.png";
	  imgArray[4] = new Image;
	  imgArray[4].src = "Giraffe.png";
	  imgArray[5] = new Image;
	  imgArray[5].src = "Elephant.png";
	  imgArray[6] = new Image;
	  imgArray[6].src = "Tiger.png";
	  cycle();
	  return;
	}




 <div align="center">
  
 </div>


What I have tried:

I also saved the pictures as jpeg and that made no difference. I do not have the option to save the pictures as gif.
Posted
Updated 1-Oct-20 9:30am
v2

At a guess, it can't find the pictures.
Check where you put them - they need to be in the same folder as the page .HTML file.
   
Comments
Member 14953455 1-Oct-20 11:38am
   
That's what I thought I did wrong at first, but I went back and resaved the pictures with the pictures from my old projects. Everything is in my web design folder and it gave me the same results.
Well, could it be this typo:
document.banner.src - imgArray[index].src;
Change this to equal to sign from a minus. As long as the images are in the same location as html file, it should pick up the value. Format should not matter.

document.banner.src = imgArray[index].src;
   
Comments
Member 14953455 1-Oct-20 14:16pm
   
That's what it was. I didn't notice that typo when I went back through my code. Thank you I appreciate the help!
Sandeep Mewara 1-Oct-20 14:47pm
   
Welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900