What is wrong with this javascript code?

  • 1
  • Question
  • Updated 7 years ago
  • Answered
Here's the script.

<script language="JavaScript">
images = new Array(4);

images[0] = '<script type="text/javascript">google_ad_client = "ca-pub-4811954214954647";google_ad_slot = "2713945203";google_ad_width = 728;google_ad_height = 90;</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';

images[1] = 'other code';

images[2] = 'other code';

images[3] = 'other code';

index = Math.floor(Math.random() * images.length);
document.write(images[index]);
//done
</script>


I have tried it repeatedly, but it does not work. What's wrong with it?
Photo of admin

admin

  • 35 Posts
  • 0 Reply Likes

Posted 7 years ago

  • 1
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Hello admin,

From where did you get this code and what is it supposed to do?
Photo of admin

admin

  • 35 Posts
  • 0 Reply Likes
I created the code. It is supposed to rotate ad boxes. Image[0] is my adsense box code, the other images are the other persons (when I insert them). This code should, in theory, display mine 25% of the time and the other person's 75% of the time.

However, this code doesn't work at all. It works with normal text and with basic html such as a href, but it doesn't work with this script.
Photo of Sanja

Sanja, Official Rep

  • 10698 Posts
  • 495 Reply Likes
Hello admin,

We don't really have the resources to assist with this. I suggest perhaps posting your question on this thread: December Code Requests.

Our HTML savvy forum members may be able to assist.
Photo of admin

admin

  • 35 Posts
  • 0 Reply Likes
Ok. I'll leave this question here just in case someone who knows how to do this sees this.