I made a script that cycles through different kinds of Adsense ads on my webpage. Originally I made a PHP/Javascript combo, but due to various reasons I need to convert it to a Javascript only code. I can't figure out why my javascript only code isn't working.
PHP/Javascript combo:
<?php
$random = (rand(0,100));
?>
<?php
if($random > 50)
{
?>
<script type="text/javascript"><!--
google_ad_client = "pub-XXXXXXXXXX0578";
//120x240, created 1/2/08
google_ad_slot = "XXXXXX136";
google_ad_width = 120;
google_ad_height = 240;
google_cpa_choice = ""; // on file
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
}
else
{
?>
<script type="text/javascript"><!--
google_ad_client = "pub-XXXXXXXXXX0578";
//120x240, created 1/2/08
google_ad_slot = "XXXXXX271";
google_ad_width = 120;
google_ad_height = 240;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
}
?>
JAVASCRIPT ONLY:
<script>
var number = Math.round(101*Math.random());
if (number > 50)
{
<!--
google_ad_client = "pub-XXXXXXXXXX0578";
//120x240, created 1/2/08
google_ad_slot = "XXXXXX136";
google_ad_width = 120;
google_ad_height = 240;
google_cpa_choice = ""; // on file
//-->
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
}
else
{
<!--
google_ad_client = "pub-XXXXXXXXXXX0578";
//120x240, created 1/2/08
google_ad_slot = "XXXXXX271";
google_ad_width = 120;
google_ad_height = 240;
//-->
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
}
</script>